用gradle发布自定义jar输出?

时间:2016-02-26 14:51:44

标签: gradle build.gradle

我有一个gradle构建脚本,它可以检索许多常见的依赖项,并创建一个“胖罐”,并将它们全部组合在一起。

  

gradle fatJar uploadArchives

然而,之后的uploadArchives步骤不使用生成的jar,而是使用没有依赖项的默认jar覆盖它。

如何指定发布步骤以使用“fat jar”而不是覆盖创建的jar?

apply plugin: 'java'
apply plugin: 'maven'

version '1.2.3'

sourceSets {
   main {
      resources.srcDirs = ["resources"]  
   }
}

repositories {
    mavenCentral()
}
dependencies {
  runtime 'commons-cli:commons-cli:1.3.1'                            
  ....
  runtime 'xerces:xercesImpl:2.11.0'

}


//create a single Jar with all dependencies
task fatJar(type: Jar) {
    manifest {
        attributes 'Implementation-Title': 'Some common jars',  
            'Implementation-Version': version
    }
    from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}



uploadArchives {
   repositories {

      mavenDeployer {
        repository(url: "http://localhost:8081/artifactory/org-sandbox") {
            authentication(userName: "admin", password:"password")
        }
        pom.groupId = 'org.something'
      }
   }

}

1 个答案:

答案 0 :(得分:1)

根据RaGe的建议,我切换到maven-publish,允许指定工件(按任务名称)。这很有效。

publishing {
  publications {
     maven(MavenPublication) {

       groupId 'org.something'

       artifact fatJar 
    }
 }

 repositories { 
  maven {
    url "http://localhost:8081/artifactory/sandbox"
    credentials { 
       username 'admin' 
       password 'password' 
    }
  }

}