[英]Gradle's Maven Publish plugin not publishing POM or proper version to Maven Local
I am trying to get the Gradle Maven Publish Plugin to publish a snapshot version of my Java library to my local Maven repo such that: 我正在尝试使用Gradle Maven Publish插件将我的Java库的快照版本发布到我的本地Maven仓库,这样:
1.0.0.SNAPSHOT-<timestamp>
, where <timestamp>
is the current system time in millis (similar to something like System.currentTimeInMillis()
); 罐的版本是1.0.0.SNAPSHOT-<timestamp>
,其中<timestamp>
是在米利斯当前系统时间(类似于像 System.currentTimeInMillis()
); and 和 My best attempt so far: 到目前为止我最好的尝试:
plugins {
id 'java-library'
id 'maven-publish'
}
dependencies {
compile(
'org.hibernate:hibernate-core:5.0.12.Final'
,'com.fasterxml.jackson.core:jackson-core:2.8.10'
,'com.fasterxml.jackson.core:jackson-databind:2.8.10'
,'com.fasterxml.jackson.core:jackson-annotations:2.8.0'
)
testCompile(
'junit:junit:4.12'
)
}
repositories {
jcenter()
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
group 'com.me'
jar {
baseName = 'my-lib'
version = '1.0.0-SNAPSHOT'
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
However, with this setup, when I run ./gradlew publishToMavenLocal
: 但是,使用此设置,当我运行./gradlew publishToMavenLocal
:
~/.m2/repository/com/me/my-lib/
but without a pom.xml and no 1.0.0.SNAPSHOT
version appended to it 我确实看到jar被部署到~/.m2/repository/com/me/my-lib/
但是没有pom.xml而没有附加1.0.0.SNAPSHOT
版本 println(...)
to report the full name of the jar being published 我甚至不知道如何/在哪里我会用println(...)
来报告正在发布的jar的全名 Any ideas? 有任何想法吗?
Regarding #3 , To install your artifact to a local repository you do not need the maven-publish
plugin, rather the maven
plugin 关于#3 ,要将工件安装到本地存储库,您不需要maven-publish
插件,而是maven
插件
See The Maven plugin documentation, specifically the Tasks section and the Installing to the local repository section with it, you can run gradle clean build install
请参阅Maven插件文档,特别是Tasks部分和使用它安装到本地存储库部分 ,您可以运行gradle clean build install
It works for me with a build.gradle file as simple as this 它对我来说很简单,只需要一个build.gradle文件
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'maven'
Note, if you need to publish something other then the default generated jar then you need to change the archives
configuration 注意,如果您需要发布除默认生成的jar之外的其他内容,则需要更改archives
配置
Regarding #1 appending the timestamp, move the version line outside the jar clause and change it from 关于附加时间戳的#1 ,将版本行移到jar子句之外并从中更改
version = '1.0.0-SNAPSHOT'
to 至
version = "1.0-SNAPSHOT-${System.currentTimeMillis()}"
This is using Groovy GString (AKA string interpolation - note the change from single quotes to double quotes ) to append the current time in millis to the version 这是使用Groovy GString(AKA字符串插值 - 注意从单引号到双引号的更改 )将当前时间以毫秒为单位附加到版本
Last but not least, regarding #2 printing the jar full name append the following to the build.gradle file 最后但并非最不重要的是,关于#2打印,jar全名会将以下内容附加到build.gradle文件中
install.doLast {
println jar.archiveName
}
Essentially we're appending to the install task (the one executed in the top of my answer) a println of the jar configuration's archiveName (see here if you want something else) 基本上我们将附加到安装任务(在我的答案的顶部执行的任务)一个jar配置的archiveName的println(如果你想要别的东西,请看这里 )
So all in all my build.gradle file looks like this: 总而言之,我的build.gradle文件如下所示:
group 'com.boazj'
version "1.0-SNAPSHOT-${System.currentTimeMillis()}"
apply plugin: 'java'
apply plugin: 'maven'
install.doLast {
println jar.archiveName
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.