使用Gradle将jar发布到MavenLocal
我正在使用Gradle使用多个Eclipse项目来管理产品的构建。
I'm using Gradle to manage the build of a product using multiple eclipse projects.
其中一些项目使用了中央存储库中不可用的jar文件(例如MavenCentral)。
Several of those projects use jar files that are not available from a central repository (like MavenCentral).
我想创建一个Eclipse项目,将这些jar文件放入其中,并建立一个build.gradle,将这些jar文件放入mavenLocal使用我指定的groupId,artifactId和版本。
I'd like to have an eclipse project that I just place those jars into, and a build.gradle that will place those jar files into mavenLocal using the groupId, artifactId and version that I specify.
这样,我可以将 mavenLocal()
添加到其他项目并指定依赖项。
This way I can just add mavenLocal()
to other projects and specify the dependency.
我有以下 build.gradle
:
apply plugin: 'maven-publish'
publishing {
publications {
maven(MavenPublication) {
groupId 'myGroupId'
artifactId 'myArtifact'
version '1.2.3'
from <how to reference jar>
}
}
}
我尝试了 file('myJar.jar')
,但是不接受。似乎Gradle想要一个from值的工件,但是我似乎找不到如何将预构建的jar文件指定为该工件。
I've tried file('myJar.jar')
, but that isn't accepted. It appears that Gradle wants an artifact for the from value, but I can't seem to find how to specify a prebuilt jar file as that artifact.
似乎应该
当前,'from'只能接受 components.java
和 components.web
。要包含一个罐子,请使用'artifact',例如:
Currently, 'from' can only accept components.java
and components.web
. To include a jar, use 'artifact', for example:
publishing {
publications {
maven(MavenPublication) {
groupId 'myGroupId'
artifactId 'myArtifact'
version '1.2.3'
artifact <path to file>
}
}
}
工件也可以接受存档任务的输出:
'artifact' can also accept output of archive tasks:
publishing {
publications {
maven(MavenPublication) {
groupId 'myGroupId'
artifactId 'myArtifact'
version '1.2.3'
artifact getlibrary
}
}
}
task getlibrary(type:Jar){
from <directory>
classifier='lib'
}