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

时间:2015-05-27 05:17:39

标签: java maven netbeans deployment gradle

我试图找出如何让gradle将一些jar文件部署到本地maven存储库,以支持构建系统的其余部分。我对某些内容的依赖关系依赖于jndi:jndi:1.2.1,这在jcenter或maven central中是不可用的。

我已经完成的事情(正如我的依赖文档中所建议的 - Jira的价值)下载了jndi.jar文件,并运行了以下内容:

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

工作正常。但我希望gradle能够执行将此文件安装到本地maven存储库的任务,以使CI更容易,并使其他开发人员更容易上手。

我试图关注recommendations herecode),但我没有太多运气。这是我的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)

当我运行安装任务时:

$ 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

现在,我真的不想将我的工件安装到本地maven存储库 - 只是传递依赖项。如果安装了我的工件,我不介意。

更新 - 解决方案:

所以,这似乎可以解决问题:

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')
}

我将libs移动到maven所期望的文件夹结构中,将本地文件夹结构添加到存储库节中,并将运行时文件添加到依赖项中。

没有填充localhost全局存储库,执行命令行或类似的东西。很高兴能够更好地支持本地传递依赖,但实际需要多长时间?

1 个答案:

答案 0 :(得分:4)

Gradle允许short-circuit evaluation,而无需先将它们安装到本地存储库。

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

那应该马上工作。最后,您可能想要设置Maven存储库管理器,例如adding dependencies directly to your build,在那里安装您缺少的库,并在您的构建中引用它们:

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"
}