StF*_*tFS 6 gradle maven-publish
我有一个多项目 gradle 构建,并且我已将该maven-publish插件应用到subprojects我的主构建文件中的所有项目。
我还在那里定义了一个名为 的默认出版物mavenJava。
这一切都很好,现在当我运行时,./gradlew artifactoryPublish我会部署所有子项目中的工件。
但是,我想将我的两个子项目排除在出版本mavenJava出版物之外。
我已经尝试了很多事情,例如在我的主构建文件中的块中定义布尔值()skipDefaultPublish,并将发布定义包含在条件 if 块中,并在我不想要的子项目块中覆盖此变量发布它。这不起作用,gradle 抱怨它。extsubprojectsextCannot configure the 'publishing' extension after it has been accessed.
我尝试过其他方法,但似乎没有任何效果。
我知道唯一可行的是在所有子项目中定义默认发布块,除了我不想发布的子项目,但我有大约 20 个子项目,但只有两个不应该发布这种类型的工件,所以这不会似乎不是最好的做法。
那么有什么方法可以配置所有子项目来发布工件,但只在其中两个子项目中覆盖它,这样它们就不会这样做?
更新
试图澄清我的项目是什么样的。
根构建.gradle
subprojects {
apply plugin: 'maven-publish'
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifactId = getCustomProjectId()
groupId = 'com.our.group.id'
}
}
}
apply plugin: "com.jfrog.artifactory"
artifactory {
contextUrl = ourContextUrl
publish {
repository {
repoKey = "ourRepoKey"
username = "ourArtifactoryUser"
password = "ourArtifactoryPass"
}
defaults {
publications('mavenJava')
publishArtifacts = true
publishPom = true
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在应该发布工件的子项目中,而不是默认的:
project(':exsub'){
publishing {
publications {
mavenSrc(MavenPublication) {
groupId "com.our.group.id"
artifactId "stuff-src"
artifact srcStuff
}
}
}
artifactoryPublish {
// publications.removeAll() //<- putting this here doesn't work
// publications.remove('mavenJava') //<- neither does this
publications ('mavenSrc') //<- this adds mavenSrc to the publication list but does not remove the mavenJava publication from it
}
}
Run Code Online (Sandbox Code Playgroud)
发布工件的方法有多种,具体取决于所使用的插件。
要通过现代 (Gradle 4.x-7.x) 之类的任务排除特定模块的发布publish:
tasks.withType(PublishToMavenRepository).configureEach { it.enabled = false }
Run Code Online (Sandbox Code Playgroud)
遗产uploadArchives:
uploadArchives.enabled = false
Run Code Online (Sandbox Code Playgroud)
带com.jfrog.artifactory插件:
artifactoryPublish.skip = true
Run Code Online (Sandbox Code Playgroud)
Kotlin 语法(tnx @jaguililla):
tasks.withType<PublishToMavenRepository>().configureEach { enabled = false }
tasks.withType<PublishToMavenLocal>().configureEach { enabled = false }
Run Code Online (Sandbox Code Playgroud)
唷...我想我终于找到了一种方法来做到这一点(该解决方案的美观性很有争议)。
publishing.publications.remove(publishing.publications.mavenJava)对我来说,在子项目中添加一条线就足够了。
但是,我必须小心将该行放在publishing{...}该子项目中的块下方。
所以现在,不应该发布“默认发布”的子项目看起来像这样:
project(':exsub'){
publishing {
publications {
mavenSrc(MavenPublication) {
groupId "com.our.group.id"
artifactId "stuff-src"
artifact srcStuff
}
}
}
// Remove the default publication (note: this must be located after the publishing block above)
publishing.publications.remove(publishing.publications.mavenJava)
artifactoryPublish {
publications ('mavenSrc') //<- this adds mavenSrc to the publication list but does not remove the mavenJava publication from it
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10114 次 |
| 最近记录: |