返回

maven publish-将一个或两个子项目从gradle中排除

发布时间:2022-06-20 09:33:34 295
# java# java

我有一个多项目的gradle构建,我已经应用了maven-publish全部插件subprojects在我的主构建文件中。

我还定义了一个名为mavenJava.

一切都很好,现在当我跑步的时候./gradlew artifactoryPublish我从所有子项目部署工件。

但是,我想排除我的两个子项目发布此mavenJava出版

我试过很多方法,比如定义布尔值(skipDefaultPublish)在ext中的块subprojects在我的主生成文件中,将发布定义包含在条件if块中,并在ext我不想发布它的子项目块。这行不通,gradle抱怨说Cannot configure the 'publishing' extension after it has been accessed..

我尝试过其他的方法,但似乎没有任何效果。

我知道唯一可行的是在所有子项目中定义默认发布块,但我不想从中发布的子项目除外,但我有大约20个子项目,但只有两个子项目不应该发布这种类型的工件,所以这似乎不是最好的做法。

那么,我有没有办法配置所有子项目来发布一个工件,但只在其中两个子项目中覆盖它,这样它们就不会发布工件了?

更新

试图弄清楚我的项目是什么样的。

root build.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
            }
        }
    }
}

在应该发布工件(而不是默认工件)的子项目中:

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
    }
}
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(2)
按点赞数排序
用户头像