lein与私有仓库

lein在new一个新的项目的时候都会从maven或者clojars上下载对应的依赖,但是一旦你离开了互联网环境只有一个maven私服的时候,这一切就变得不是那么美好了。因此,我们需要配置一下lein,让它能够从我们指定的位置下载依赖。

创建profiles.clj

在$HOME/.lein/下创建profiles.clj文件,在其中添加如下内容:

{
 :user {
        :mirrors {
                  "central" {
                             :name "nexus-maven"
                             :url "https://ip:port/repository/maven-central/"
                             }
                  "clojars" {
                             :name "nexus-clojure"
                             :url "https://ip:port/repository/clojars/"
                             }
                  }
	:certificates ["path of nexus.pem"]
        }
 }

clojure默认是不允许使用http的仓库,因此必须使用https的链接,并在certificates里配置相应的证书,这样lein在加载依赖的时候就可以自动通过设置的maven仓库下载依赖了。

配置nexus使用https

根据官方文档中说明,需要进行如下步骤:

  1. 在$install-dir/etc/ssl/下创建keystore文件keystore.jks

  2. 在$data-dir/etc/nexus.properties文件中添加 application-port-ssl=8443

  3. 在$data-dir/etc/nexus.properties文件nexus-args属性中添加${jetty.etc}/jetty-https.xml,如下所示:

    nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml, \ 
    ${jetty.etc}/jetty-https.xml,${jetty.etc}/jetty-requestlog.xml
    
  4. 在$install-dir/etc/jetty/jetty-https.xml中配置keystore文件的密码,如果你没有设置keystore的密码这一步就可以忽略

到这一步位置其实nexus的https就已经配置好了,但是lein的certificates的证书貌似需要使用pem文件,因此需要自己转换成pem文件并放在自己指定的路径下就可以了。

keystore文件生成和转换

官方文档中其实包含证书生成的内容,我这里就进行简单的copy了 XD。

  1. 生成证书库和证书:
keytool -genkeypair -keystore example.jks -storepass password -alias \  
example.com -keyalg RSA -keysize 2048 -validity 5000 -keypass password \ 
-dname 'CN=*.example.com, OU=Sonatype, O=Sonatype, L=Unspecified, \ 
ST=Unspecified, C=US' -ext \ 
'SAN=DNS:nexus.example.com,DNS:clm.example.com,DNS:repo.example.com, \ 
DNS:'www.example.com'
  1. 转换为PKCS12证书:
keytool -importkeystore -srckeystore example.jks -destkeystore example.p12 -deststoretype PKCS12
  1. 将PKCS12证书转换为openssl证书:
openssl pkcs12 -nokeys -in example.p12 -out example.pem

通过以上步骤就完成了pem证书的生成,然后在profiles.clj中certificates属性里进行配置就可以了。

完结撒花★,°:.☆( ̄▽ ̄)/$:.°★