简体   繁体   English

用于将销售库部署到本地maven存储库的Gradle任务

[英]Gradle task for deploying vendored libraries into local maven repository

I'm trying to figure out how to get gradle to deploy some jar files into the local maven repository, to support the rest of the build system. 我正在试图找出如何让gradle将一些jar文件部署到本地maven存储库中,以支持构建系统的其余部分。 A dependency that I have against something has its own dependency on jndi:jndi:1.2.1 which isn't available in jcenter or maven central. 我对某些东西的依赖关系依赖于jndi:jndi:1.2.1在jcenter或maven central中不可用。

What I've done (as suggested in the docs of my dependency - Jira for what it's worth) is downloaded the jndi.jar file, and have run the following: 我已经完成了(正如我的依赖文档中所建议的 - Jira的价值)下载了jndi.jar文件,并运行了以下内容:

mvn install:install-file -Dfile=lib/jndi.jar -DgroupId=jndi \
-DartifactId=jndi -Dversion=1.2.1 -Dpackaging=jar

That works fine. 这很好。 But I'd like gradle to be able to execute a task that will install this file to the local maven repository, to make CI easier and to make on-boarding other developers easier. 但我希望gradle能够执行将此文件安装到本地maven存储库的任务,以使CI更容易,并使其他开发人员更容易上手。

I've tried to follow the recommendations here (with code ), but I'm not having much luck. 我试图按照这里建议 (带代码 ),但我没有太多运气。 Here's an excerpt from my build.gradle: 这是我的build.gradle的摘录:

apply plugin: 'java'
apply plugin: 'maven'

artifacts {
    archives(file('lib/jndi.jar')) {
        name 'jndi'
        group 'jndi'
        version '1.2.1'
    }
    archives(file('lib/jta-1_0_1B.jar')) {
        name 'jta'
        group 'jta'
        version '1.0.1'
    }
}

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: 'file://' + new File(System.getProperty('user.home'), '.m2/repository').absolutePath)
        }
    }
}
install.dependsOn(uploadArchives)

And when I run the install task: 当我运行安装任务时:

$ gradle --version

------------------------------------------------------------
Gradle 2.4
------------------------------------------------------------

Build time:   2015-05-05 08:09:24 UTC
Build number: none
Revision:     5c9c3bc20ca1c281ac7972643f1e2d190f2c943c

Groovy:       2.3.10
Ant:          Apache Ant(TM) version 1.9.4 compiled on April 29 2014
JVM:          1.8.0_11 (Oracle Corporation 25.11-b03)
OS:           Mac OS X 10.10.3 x86_64

$ gradle install
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:uploadArchives FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':uploadArchives'.
> Could not publish configuration 'archives'
   > A POM cannot have multiple artifacts with the same type and classifier. Already have MavenArtifact engage-jira:jar:jar:null, trying to add MavenArtifact engage-jira:jar:jar:null.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Now, I don't really want to install my artifacts to the local maven repository - just the transitive dependencies. 现在,我真的不想将我的工件安装到本地maven存储库 - 只是传递依赖项。 I don't mind if my artifact is installed though. 我不介意我的神器是否安装了。

Update - Solution: 更新 - 解决方案:

So, this seems to do the trick: 所以,这似乎可以解决问题:

repositories {
    jcenter()

    maven { 
        url './lib' 
    }
}

dependencies {
    runtime files(
       'lib/jndi/jndi/1.2.1/jndi-1.2.1.jar', 
       'lib/jta/jta/1.0.1/jta-1_0_1.jar'
    )
    runtime fileTree(dir: 'lib', include: '*.jar')
}

I moved the libs into the folder structure expected by maven, added the local folder structure into the repositories stanza, and added the runtime files into dependencies. 我将libs移动到maven所期望的文件夹结构中,将本地文件夹结构添加到存储库节中,并将运行时文件添加到依赖项中。

No stuffing about with the localhost global repository, executing command lines, or anything like that. 没有填充localhost全局存储库,执行命令行或类似的东西。 It'd nice to have better support for local transitive dependencies, but how often is that required in practise? 很高兴能够更好地支持本地传递依赖,但实际需要多长时间?

Gradle allows adding dependencies directly to your build , without first installing them to the local repository. Gradle允许直接向构建添加依赖项 ,而无需先将它们安装到本地存储库。

dependencies {
    runtime files('lib/jndi.jar', 'lib/jta-1_0_1B.jar')
    runtime fileTree(dir: 'lib', include: '*.jar')
}

That should work right away. 这应该马上工作。 Eventually, you might want to set up a Maven repository manager, eg Artifactory , install your missing libraries there, and refer to them in your build like this: 最后,您可能想要设置一个Maven存储库管理器,例如Artifactory ,在那里安装您缺少的库,并在您的构建中引用它们,如下所示:

repositories {
    maven { url "http://192.168.x.x/artifactory/local-repository" }
    mavenCentral()
}

dependencies {
    compile "jndi:jndi:1.2.1"
    compile "jta:jta:1.0.1"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM