Using Gradle to publish jars to MavenLocal

徘徊边缘 提交于 2020-02-05 04:34:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!