使用Gradle将jar发布到MavenLocal [英] Using Gradle to publish jars to MavenLocal

查看:562
本文介绍了使用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'
}

这篇关于使用Gradle将jar发布到MavenLocal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆