标签:
Maven作为目前Java界最好的Dependency管理系统,把jar包托管到Maven中央库,然后通过Maven Dependency使用是目前业界各种第三方库的普遍做法,如果,你想把自己开发的一些库分享给别人使用,也可以遵循这样的套路。Gradle可以看做是升级版的Maven,其使用了Maven最优秀的Dependency管理系统,但是,又规避了Maven的build pipeline的刻板和xml格式配置文件等缺点,可以说是目前Java界最好的构建工具。下面就来说说,如何使用Gradle把自己开发的jar包部署到Maven中央库中。apply plugin: ‘idea‘ apply plugin: ‘java‘ apply plugin: ‘maven‘ apply plugin: ‘signing‘ //使用signing plugin做数字签名 //定义GroupID和Version,ArtefactID会自动使用Project名 group = ‘com.thoughtworks.toggle‘ version = ‘0.1.0-SNAPSHOT‘ sourceCompatibility = 1.6 targetCompatibility = 1.6 repositories { mavenCentral(); } dependencies { compile( ‘junit:junit:4.11‘, ) } uploadArchives { repositories { mavenDeployer { //为Pom文件做数字签名 beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } //指定项目部署到的中央库地址,UserName和Password就是Part 1中注册的账号。 repository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { authentication(userName: sonatypeUsername, password: sonatypePassword) } //构造项目的Pom文件,参见Part 2中Pom文件的规范,不要遗漏必填项 pom.project { name project.name packaging ‘jar‘ description ‘Toggle is a little java tool to make your life easier when you try to use Feature Toggle in Java.‘ url ‘https://github.com/xianlinbox/Toggle‘ scm { url ‘scm:git@github.com:xianlinbox/Toggle.git‘ connection ‘scm:git@github.com:xianlinbox/Toggle.git‘ developerConnection ‘git@github.com:xianlinbox/Toggle.git‘ } licenses { license { name ‘The Apache Software License, Version 2.0‘ url ‘http://www.apache.org/licenses/LICENSE-2.0.txt‘ distribution ‘repo‘ } } developers { developer { id ‘xianlinbox‘ name ‘Liu Xiannings‘ } } } } } } //参见Part 2, 为项目生成**.jar/**-javadoc.jar/**-sources.jar task javadocJar(type: Jar, dependsOn: javadoc) { classifier = ‘javadoc‘ from ‘build/docs/javadoc‘ } task sourcesJar(type: Jar) { classifier = ‘sources‘ from sourceSets.main.allSource } artifacts { archives jar archives javadocJar archives sourcesJar } //为所有的jar包做数字签名 signing { sign configurations.archives }
cd $(/usr/libexec/java_home -v 1.7)/jre/lib/security ln -fsh /System/Library/Java/Support/CoreDeploy.bundle/Contents/Home/lib/security/cacerts
标签:
原文地址:http://my.oschina.net/boltwu/blog/425594