0

我的项目中有一个 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.gradlepom正确的。

4

1 回答 1

0

尝试使用以下命令覆盖所有publishing块:

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

            artifact sourceJar {
                classifier "sources"
            }
        }
    }
}
于 2017-10-05T10:11:08.990 回答