我正在试图找出如何让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 here(code),但我没有太多运气.这是我的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全局存储库,执行命令行或类似的东西.很高兴能够更好地支持本地传递依赖,但实际需要多长时间?
解决方法:
Gradle允许adding dependencies directly to your build,而无需先将它们安装到本地存储库.
dependencies {
runtime files('lib/jndi.jar', 'lib/jta-1_0_1B.jar')
runtime filetree(dir: 'lib', include: '*.jar')
}
这应该马上工作.最后,您可能想要设置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"
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。