我的项目中有一个 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
是正确的。
最佳答案
尝试覆盖所有 publishing
阻止:
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourceJar {
classifier "sources"
}
}
}
}
关于gradle - 读取外部 .gradle 文件时发布源 jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46582096/