问题
I'm using Gradle to manage the build of a product using multiple eclipse projects.
Several of those projects use jar files that are not available from a central repository (like MavenCentral).
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.
This way I can just add mavenLocal()
to other projects and specify the dependency.
I have the following build.gradle
:
apply plugin: 'maven-publish'
publishing {
publications {
maven(MavenPublication) {
groupId 'myGroupId'
artifactId 'myArtifact'
version '1.2.3'
from <how to reference 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.
Seems like it ought to be pretty simple, but I'm not finding it.
回答1:
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'
}
来源:https://stackoverflow.com/questions/39662663/using-gradle-to-publish-jars-to-mavenlocal