使用gradle上传jar到本地Maven仓库 [英] Use gradle to upload jar to local Maven repository

查看:66
本文介绍了使用gradle上传jar到本地Maven仓库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题已经被问过好几次了,但不知何故我没有让它起作用.Gradle 是一个很棒的工具,但它的文档并不好.对于不经常使用它的人来说,没有任何例子几乎无法理解.

This question has been asked several times, but somehow I don't get this to work. Gradle is a great tool, but its documentation is anything but great. No examples make it almost impossible to understand for someone who doesn't use it on a daily basis.

我正在使用 Android Studio,我想将我的模块输出 jar 上传到我的本地 Maven 存储库.

I am using Android Studio and I want to upload my module output jar to my local Maven repository.

apply plugin: 'java'

dependencies {
    compile 'com.google.http-client:google-http-client-android:1.18.0-rc'
}


apply plugin: 'maven'
configure(install.repositories.mavenInstaller) {
    pom.project {
        groupId 'com.example'
        artifactId 'example'
        packaging 'jar'
    }
}

当我在 Android Studio 中开始构建时,我可以在 Gradle 选项卡上看到

When I start a build in Android Studio, I can see on the Gradle tab that

:install

被调用.我的构建文件夹中也有一个新的 jar,但该 jar 没有上传到 Maven.[Maven 存储库存在并且 Google appengine gradle 插件从同一项目的另一个模块上传它的 jar 就好了.]

is invoked. I also get a new jar in my build folder, but that jar is not uploaded to Maven. [The Maven repo exists and the Google appengine gradle plugin uploads its jar from another module of the same project just fine.]

我错过了什么?

推荐答案

我怀疑问题是你只是在编辑 POM(通过 pom.project),而不是配置实际的 Maven 坐标用于安装.请尝试以下操作:

I suspect the problem is that you are only editing the POM (via pom.project), instead of configuring the actual Maven coordinates used for installation. Try the following instead:

// best way to set group ID
group = 'com.example'

install {
    repositories.mavenInstaller {
        // only necessary if artifact ID diverges from project name
        // the latter defaults to project directory name and can be
        // configured in settings.gradle
        pom.artifactId = 'myName' 
        // shouldn't be needed as this is the default anyway
        pom.packaging = 'jar'
    }
}

PS:完整 Gradle 发行版中的 samples 目录包含许多示例构建,也用于 maven 插件.

PS: The samples directory in the full Gradle distribution contains many example builds, also for the maven plugin.

这篇关于使用gradle上传jar到本地Maven仓库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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