Gradle:如何将自定义JAR文件上传到Maven存储库 [英] Gradle: How to upload custom JAR file to Maven repository
问题描述
我不使用Gradle Jar任务构建一个jar文件(我需要在我的任务中使用Ant任务)。
我试图用默认工件覆盖
uploadArchives {
repositories {
mavenDeployer {
//一些Maven配置
}
}
}
$ b artifacts {
archives file:file('bin / result.jar')
}
但是我收到一个错误,说明可能不会有两个具有相同类型和分类器的工件,这意味着此配置增加了相当重要的配置。
解决方案 http://gradle.org/docs/current/javadoc/org/gradle/api/artifacts/dsl/ArtifactHandler.html\">ArtifactHandler API )。
您有两个选择:
1)按照添加工件过滤器gradle.org/docs/current/userguide/maven_plugin.html#uploading_to_maven_repositories\">此处(请参阅章节。 45.6.4.1。 每个项目有多个工件)。如果你使用这个,试着声明你的档案
配置,如:
artifacts {
archives file:file('bin / result.jar'),name:'result',type:'jar'
}
$ c
$ b $ p
$ b $ p
$ b $ pref = lang-groovy prettyprint-override> addFilter('result'){artifact,file - >
artifact.name =='result'
}
<2>上传它作为一个独立的Maven模块。如果 result.jar
是您上传的唯一jar文件,那么这可能是一个很好的解决方案。 $ b
配置{
resultArchives
}
uploadResultArchives {
储存库{
mavenDeployer {
存储库(url:same / url / here)
}
}
}
artifacts {
resultArchives file:file('bin / result .jar')
}
希望这有助于您。
I build a jar file without using Gradle Jar task (I need to be using Ant task for that inside my task). How do I configure uploadArchives to be able to install JAR in specified repository.
I have tried to override default artifact with
uploadArchives {
repositories {
mavenDeployer {
// some Maven configuration
}
}
}
artifacts {
archives file: file('bin/result.jar')
}
but I'm getting an error that there may not be 2 artifacts with the same type and classifier, which means this configuration adds rather that overrides configuration.
You are right, artifacts
closure can only add artifacts to the given configuration (see ArtifactHandler API).
You have two options:
1) Add an artifact filter as described here (see ch. 45.6.4.1. "Multiple artifacts per project"). If you use this, try declaring your archives
configuration like:
artifacts {
archives file: file('bin/result.jar'), name: 'result', type: 'jar'
}
This way, you something like this in your artifact filter:
addFilter('result') {artifact, file ->
artifact.name == 'result'
}
2) Upload it as a separate maven module. If result.jar
is the only jar you are uploading this may be a good solution.
configurations {
resultArchives
}
uploadResultArchives {
repositories {
mavenDeployer {
repository(url: "same/url/here")
}
}
}
artifacts{
resultArchives file: file('bin/result.jar')
}
Hope this helps.
这篇关于Gradle:如何将自定义JAR文件上传到Maven存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!