问题描述
如何使用给定的 (prêt-à-porter) POM 文件发布工件? 如果可能,请在调用发布任务之前告知何时以及如何设置它。
解决方法
在 Gradle 中,有工件 jar 和相应的自定义 POM,您不能像在 Maven 中那样发布它们:
mvn deploy:deploy-file
-DgroupId=<group-id>
-DartifactId=<artifact-id>
-Dversion=<version>
-DpomFile=<path-to-pom> <====== customized POM
-Dfile=<path-to-file>
-DrepositoryId=<id-to-map-on-server-section-of-settings.xml>
-Durl=<url-of-the-repository-to-deploy>
你不能从 build.gradle 脚本中做到这一点,我认为即使是任何插件也无法做到这一点。
功能可以在 AbstractPublisher 类中,但您不能子类化该类,添加功能实现并插入自定义发布者以用于 publishPublicationToMavenRepository 任务。
你可以做的(如果你有一个带有依赖项的 jar 项目)是破解构建阶段,正是 jaring 步骤:
jar.finalizedBy(project.tasks.setYourPom)
在哪里
task setYouPom(type: DefaultTask ){
.....you substitute your JAR by renaming
and the POM you are getting for free ;) in the Publication
}