作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Gradle 中的问题
我有这个 build.gradle
在名为 proj
的目录中:
apply plugin: 'java'
apply plugin: 'java-library-distribution'
repositories {
mavenCentral()
}
dependencies {
compile 'com.davfx:util:1.0.0'
compile 'org.johnnei:util:1.0.0'
}
gradle installDist
并找到目录
build/install/proj/lib
只包含一个
util-1.0.0.jar
.我期待两个
util-1.0.0.jar
文件,但我认为由于文件系统的工作方式,这是不可能的。
pom.xml
,然后运行
mvn dependencies:copy-dependencies
在同一个目录中。观察
target/dependency
目录只包含一个文件
util-1.0.0.jar
.但是,与 Gradle 不同的是,Maven 可以通过
prependGroupId 解决这个问题。 . (信用在评论部分归功于图纳基。)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.spacetimecat</groupId>
<artifactId>example</artifactId>
<version>0.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.davfx</groupId>
<artifactId>util</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.johnnei</groupId>
<artifactId>util</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>
G:A:1.2.3
, H:A:1.2.3
, P
这取决于这两者。我只有一个
web-1.7.0.jar
当我组装一个分发包(一个包含我的项目 jar 及其所有可传递依赖项的包)时的文件。问题是:依赖项中的 jar 文件之一被覆盖,因为它们具有相同的文件名,因为 Gradle/Maven 默认将这些 jar 命名为
artifactId-version-classifier.jar
,虽然他们有不同的组。
最佳答案
这很困惑,但您可以针对 tempCompile
声明您的依赖项配置然后添加一个 renamejars
任务到DAG
将 jar 重命名为 $buildDir/renamedJars
目录。 compile
然后配置可以包含来自 $buildDir/renamedJars
的 jars目录。
重要 - 此解决方案将丢失所有依赖项的组/工件/版本,这意味着下游项目将无法执行依赖项解析。
configurations {
tempCompile
}
dependencies {
tempCompile 'com.davfx:util:1.0.0'
tempCompile 'org.johnnei:util:1.0.0'
compile fileTree("$buildDir/renamedJars")
}
task renameJars {
inputs.files configurations.tempCompile
outputs.dir "$buildDir/renamedJars"
doLast {
mkdir "$buildDir/renamedJars"
ResolvedConfiguration rc = configurations.tempCompile.resolvedConfiguration
Set<ResolvedArtifact> artifacts = rc.resolvedArtifacts
artifacts.each { ra ->
ModuleVersionIdentifier mvi = ra.moduleVersion.id
copy {
from ra.file
into "$buildDir/renamedJars"
rename { old ->
return "${mvi.group}-${mvi.name}-${ra.classifier}-${mvi.version}.${ra.extension}"
}
}
}
}
}
compileJava.dependsOn renameJars
关于gradle installDist : How do I prepend the group id to dependency jar name (clashing due to different group id but same artifact id and version)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42174572/
我是一名优秀的程序员,十分优秀!