Jos*_*ton 5 java deployment netbeans gradle maven
我试图弄清楚如何让 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
Run Code Online (Sandbox Code Playgroud)
这很好用。但我希望 gradle 能够执行一个任务,将这个文件安装到本地 maven 存储库,使 CI 更容易,并使其他开发人员更容易入职。
我尝试遵循此处的建议(使用代码),但运气不佳。这是我的 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)
Run Code Online (Sandbox Code Playgroud)
当我运行安装任务时:
$ 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
Run Code Online (Sandbox Code Playgroud)
现在,我真的不想将我的工件安装到本地 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')
}
Run Code Online (Sandbox Code Playgroud)
我将库移动到 maven 期望的文件夹结构中,将本地文件夹结构添加到存储库节中,并将运行时文件添加到依赖项中。
无需使用 localhost 全局存储库、执行命令行或类似内容。对本地传递依赖有更好的支持会很好,但在实践中需要多长时间?
Gradle 允许将依赖项直接添加到您的构建中,而无需先将它们安装到本地存储库。
dependencies {
runtime files('lib/jndi.jar', 'lib/jta-1_0_1B.jar')
runtime fileTree(dir: 'lib', include: '*.jar')
}
Run Code Online (Sandbox Code Playgroud)
那应该立即起作用。最终,您可能想要设置一个 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"
}
Run Code Online (Sandbox Code Playgroud)