使用 gradle 发布到 maven 时删除附加到工件名称的默认 date.time
Posted
技术标签:
【中文标题】使用 gradle 发布到 maven 时删除附加到工件名称的默认 date.time【英文标题】:Remove default date.time appending to artifact name when publishing to maven with gradle 【发布时间】:2016-11-22 15:01:01 【问题描述】:我正在使用带有 maven-publish 插件的 gradle 将工件发布到我们的本地 maven 存储库。
我的build.gradle
看起来像(sn-p):
apply plugin: 'java'
apply plugin: 'maven-publish'
publishing
publications
mavenJava(MavenPublication)
groupId 'org.myorg'
artifactId 'myapp'
version '0.0.1-SNAPSHOT'
from components.java
repositories
maven
credentials
username 'myUsername'
password 'myPassword'
url 'https://my.repo/snapshots/'
运行publish
后,输出如下:
$ gradle publish
:generatePomFileForMavenJavaPublication
:processResources UP-TO-DATE
:compileJava UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:publishMavenJavaPublicationToMavenRepository
Upload https://my.repo/snapshots/org/myorg/myapp/0.0.1-SNAPSHOT/myapp-0.0.1-20161122.144856-2.jar
Upload https://my.repo/snapshots/org/myorg/myapp/0.0.1-SNAPSHOT/myapp-0.0.1-20161122.144856-2.jar.sha1
Upload https://my.repo/snapshots/org/myorg/myapp/0.0.1-SNAPSHOT/myapp-0.0.1-20161122.144856-2.jar.md5
Upload https://my.repo/snapshots/org/myorg/myapp/0.0.1-SNAPSHOT/myapp-0.0.1-20161122.144856-2.pom
Upload https://my.repo/snapshots/org/myorg/myapp/0.0.1-SNAPSHOT/myapp-0.0.1-20161122.144856-2.pom.sha1
Upload https://my.repo/snapshots/org/myorg/myapp/0.0.1-SNAPSHOT/myapp-0.0.1-20161122.144856-2.pom.md5
Upload https://my.repo/snapshots/org/myorg/myapp/0.0.1-SNAPSHOT/maven-metadata.xml
Upload https://my.repo/snapshots/org/myorg/myapp/0.0.1-SNAPSHOT/maven-metadata.xml.sha1
Upload https://my.repo/snapshots/org/myorg/myapp/0.0.1-SNAPSHOT/maven-metadata.xml.md5
Upload https://my.repo/snapshots/org/myorg/myapp/maven-metadata.xml
Upload https://my.repo/snapshots/org/myorg/myapp/maven-metadata.xml.sha1
Upload https://my.repo/snapshots/org/myorg/myapp/maven-metadata.xml.md5
:publish
BUILD SUCCESSFUL
Total time: 8.147 secs
文件存在并且一切都“很好”。并不真地。 pom
等文件附加了 date.time
。有没有办法不附加它们?
我遇到的问题是,当我尝试使用 sbt
向这个新库添加依赖项时,由于附加的日期和时间,它无法获取它。
谢谢!
【问题讨论】:
【参考方案1】:这是预期的行为。当您发布快照时,maven 将在后台重命名文件,以便始终可以通过 -SNAPSHOT
引用最新的文件
如果您尝试释放您的 jar,那么只需删除 -SNAPSHOT
,您就会看到它按原样上传,名称为 "$project.name-$project.version"
。
另一方面,如果您想将 jar 引用为快照,那么您只需要确保已将快照存储库添加到您的 gradle 中
repositories
jcenter()
url 'https://my.repo/snapshots/'
dependencies
compile "some.thing:blah:1.0-SNAPSHOT"
【讨论】:
以上是关于使用 gradle 发布到 maven 时删除附加到工件名称的默认 date.time的主要内容,如果未能解决你的问题,请参考以下文章
使用 Gradle 和 Spring Boot 时无法发布到本地 maven 存储库
Android Studio Gradle:请从您的构建脚本中删除 `jcenter()` Maven 存储库的使用/JCenter 已结束生命周期