2017-10-05 71 views
0

我的項目中有一個git子模塊(其中我無法控制),其中包含名爲publish.gradle的文件。這個文件的內容是:當讀取外部.gradle文件時發佈源代碼庫

apply plugin: 'com.jfrog.artifactory' 
apply plugin: 'maven-publish' 

version = System.getenv()['VERSION'] ?: version 

publishing { 
    publications { 
     mavenJava(MavenPublication) { 
      from components.java 
     } 
    } 
} 

artifactory { 
    contextUrl = repoBaseUrl 
    publish { 
     String publishRepoKey = version.endsWith('SNAPSHOT') ? repoKeySnapshot : repoKeyRelease 
     repository { 
      repoKey = publishRepoKey // The Artifactory repository key to publish to 
      username = System.getenv()['ARTIFACTORY_USERNAME'] ?: artifactoryUser // The publisher user name 
      password = System.getenv()['ARTIFACTORY_PASSWORD'] ?: artifactoryPassword // The publisher password 
     } 
     defaults { 
      publications('mavenJava') 
      publishArtifacts = true 
      publishPom = true 
     } 
    } 
    resolve { 
     repoKey = repoKey 
    } 
} 

在我build.gradle文件我有以下行:

apply from: "${rootDir}/submodule/gradle/publish.gradle"

當我嘗試這行後添加以下行:

task sourceJar(type: Jar) { 
    from sourceSets.main.allJava 
} 

publishing.publications.mavenJava.artifact sourceJar { 
    classifier 'sources' 
} 

然後發佈正確的東西,除了存儲庫中的pom文件僅包含<dependencyManagement/>部分和所有依賴關係都丟失了。當我從build.gradle刪除上述行時,pom是正確的。

回答

0

嘗試覆蓋與所有publishing塊:

publishing { 
    publications { 
     mavenJava(MavenPublication) { 
      from components.java 

      artifact sourceJar { 
       classifier "sources" 
      } 
     } 
    } 
} 
+0

我想到這一點,但我不希望覆蓋,但如果這是唯一的方法... – mmjmanders