我有多项目Gradle配置:
-- root (folder 'gradle_test')
L--wrapper (depends on some 3rd-party maven libs)
L--module1 (depends on wrapper)
L--app
我需要在本地maven仓库中发布module1 jar(以及包装jar作为传递依赖)。
root build.gradle
:
// for maven
ext {
groupId = 'mygroup'
version = '3.0'
}
包装build.gradle
:
apply plugin: 'maven'
...
// maven pom
install {
repositories.mavenInstaller {
pom.groupId = rootProject.ext.groupId
pom.artifactId = 'wrapper'
pom.version = rootProject.ext.version
}
}
module1 build.gradle
:
dependencies {
compile project(':wrapper')
...
}
// maven pom
install {
repositories.mavenInstaller {
pom.groupId = rootProject.ext.groupId
pom.artifactId = 'module1'
pom.version = rootProject.ext.version
}
}
在将module1安装到本地maven缓存时,我可以看到依赖于' wrapper'模块生成错误(未指定版本)。 repo中的module1 pom.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>mygroup</groupId>
<artifactId>module1</artifactId>
<version>3.0</version>
<dependencies>
<dependency>
<groupId>gradle_test</groupId> // error 1: gradle project name (instead of overriden mvn groupId)
<artifactId>wrapper</artifactId>
<version>unspecified</version> // error 2: not set at all
<scope>compile</scope>
</dependency>
</dependencies>
</project>
换句话说,Gradle不会对从compile project(:wrapper)
声明映射的maven依赖项使用maven模块groupId / artifactId / version。
我该怎么做/修复它?
答案 0 :(得分:0)
我必须为wrapper
和module1
撰写:
// mvn
group = rootProject.ext.groupId
version = rootProject.ext.version
你可以删除:
install {
repositories.mavenInstaller {
...
}
}
因为Gradle会将project.group
用作mvn模块groupId
而将project.version
用作mvn模块version
:
https://docs.gradle.org/current/userguide/maven_plugin.html#sec:maven_pom_generation