读取外部.gradle文件时发布源jar

时间:2017-10-05 09:24:19

标签: gradle artifactory maven-publish

我的项目中有一个git子模块(我无法控制),其中包含名为publish.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是正确的。

1 个答案:

答案 0 :(得分:0)

尝试使用:

覆盖所有-Djdk.attach.allowAttachSelf=true
publishing