3

我有一个多项目 gradle 构建,并且我已将该maven-publish插件应用于subprojects我的主构建文件中的所有内容。

我还在那里定义了一个名为mavenJava.

这一切都很好,现在当我运行时,我./gradlew artifactoryPublish从所有子项目中部署工件。

但是,我想将我的两个子项目排除在发布此mavenJava出版物之外。

我已经尝试了很多事情,例如在我的主构建文件的块中的块中定义一个布尔skipDefaultPublishext(发布它。这不起作用,gradle 抱怨它。subprojectsextCannot 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
            }
        }
    }
}

在一个应该发布工件的子项目中,而不是默认的:

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
    }
}
4

4 回答 4

2

根据使用的插件,有多种发布工件的方法。

要排除特定模块与现代(Gradle 4.x-7.x)publish类似任务的发布:

tasks.withType(PublishToMavenRepository).configureEach { it.enabled = false }

遗产uploadArchives

uploadArchives.enabled = false

com.jfrog.artifactory插件:

artifactoryPublish.skip = true
于 2021-03-17T11:38:34.800 回答
0

在您要排除的子项目上设置以下内容对我有用:

project.tasks.publish.enabled = false

这仍然需要将maven-pulish插件应用于项目,但不需要额外的配置。

我在这里找到了这个设置:https ://discuss.gradle.org/t/disable-maven-publish-related-tasks-not-possible/13488

于 2019-11-28T22:56:03.980 回答
0

让我们考虑以下多模块项目结构。

 photos:
   -> photo-client
   -> photo-model
   -> photo-service

在上面的多模块项目中,如果我想排除照片服务子模块构建 jar(任何分发文件(jar/war))的功能上传到配置的工件,那么我们必须在照片中使用下面的代码片段-服务build.gradle文件

build.gradle

dependencies {
   .....
}

project.afterEvaluate {
    project.tasks.artifactoryPublish.enabled(false)
}

于 2020-09-08T14:47:25.837 回答
0

呼……我想我终于找到了一种方法来做到这一点(解决方案的美学是值得商榷的)。

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
    }
}
于 2019-04-08T19:02:18.730 回答