关于 Maven Publish Gradle 插件的问题?

Question about Maven Publish Gradle plugin?

很多前 DevOps 和开发人员建立了我公司的 Gradle 基础设施,在我加入之前就已经离开了,所以目前没有人知道他们做了很多事情。我是一个正在努力学习 Gradle 的 Maven 人,所以我有几个问题,我公司似乎没有人知道答案。例如,我在 build.gradle

中有以下内容
jar {
    manifest {
        attributes 'artifactId': artifactId,
                      'groupId': project.group,
                      'version': project.version
    }
    baseName artifactId
}
publishing {
    publications {
        coreComponent(MavenPublication) {
            artifactId artifactId
            from components.java
        }
    }
}

通常我希望看到 maven(MavenPublication) {} 但为什么 coreComponent(MavenPublication) {}? Where/what/how 我能找出 coreComponent 是什么吗?

Normally I expect to see maven(MavenPublication) {} but why coreComponent(MavenPublication) {}? Where/what/how do I find out what coreComponent is?

它只是出版物的名称,只有当您的项目有多个可能单独发布的出版物时,它才重要。 Gradle 将语句 coreComponent(MavenPublication) {...} 转换为对方法 create(String name, Class<U> type, Action<? super U> configuration) of the PublicationContainer. The call creates a new publication of the type MavenPublication 和名称 'coreComponent' 的调用,并使用传递的 configuration.

对其进行配置

发布名称可以任意选择,主要用于生成发布任务的名称,例如publish<PubName>PublicationToMavenLocal。在您的项目上调用 gradle tasks,您将看到它包含一个名为 publishCoreComponentPublicationToMavenLocal 的任务。由于很多项目只有一个出版物,他们使用 'maven' 作为出版物名称,但这与真正的约定相去甚远。

发布存储库使用类似的机制,因为任何发布都可以发布到多个存储库。在内部,存储库有另一个(较旧的)API,因此您不能像上面那样使用符号 <name>(<Type>)。相反,您可以创建 MavenArtifactRepository using the method maven() 类型的存储库并使用配置操作为它们分配名称:

publishing {
    repositories {
        maven {
            name = 'bintray'
            // ...
        }
        maven {
            name = 'github'
            // ...
        }
    }
}

Gradle 然后为 MavenPublicationMavenArtifactRepository 的每个组合创建一个名为 publish<PubName>PublicationTo<RepoName>Repository 的发布任务,结果是任务 publishCoreComponentPublicationToBintrayRepositorypublishCoreComponentPublicationToGithubRepository.