2016-02-26 37 views
2

我有一個gradle構建腳本,用於檢索一些常見的依賴關係,並將它們全部組合起來創建一個「fat jar」。使用gradle發佈自定義jar輸出?

gradle這個fatJar uploadArchives

然而uploadArchives步以後不使用所產生的罐子,而是與現在沒有依賴關係的默認罐子將其覆蓋。

如何指定發佈步驟以使用「胖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' 
     } 
    } 

} 
+0

你要發佈這兩個罐子?或只有胖的?順便說一句,gradle有一個更新的['maven-publish'](https://docs.gradle.org/current/userguide/publishing_maven.html)插件,它比您使用的'maven'插件處理定製要好一點。 – RaGe

+0

只有胖子......看着maven jar覆蓋fatJar步驟創建的jar的過程。 –

+0

您可以隨時更改其中的一個文件名。 – RaGe

回答

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' 
    } 
    } 

}