将所有libs版本移动到多模块渐变项目中的根渐变文件中



我有一个带模块的gradle项目。

-RootProject
-my-server(spring boot 2server)
-my-generator(module)

现在我的根项目的gradle文件如下:

group = 'com.mayprojekt'
version = '0.0.1-SNAPSHOT'

渐变设置文件如下所示:

rootProject.name = 'root-project'
include 'my-generator'
include 'my-server'

我的服务器的gradle文件看起来像这样:

buildscript {
ext {
springBootVersion = '2.0.3.RELEASE'
cxfVersion = '3.2.2'
uuidGeneratorVersion = '3.1.5'
commonLang3Version = '3.7'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group 'com.mayprojekt'
version '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
mavenLocal()
}
bootJar {
mainClassName = 'com.mayprojekt.Application'
archiveName = 'my-server.jar'
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter'
compile "org.apache.cxf:cxf-spring-boot-starter-jaxws:${cxfVersion}"
compile "com.fasterxml.uuid:java-uuid-generator:${uuidGeneratorVersion}"
compile "org.apache.cxf:cxf-rt-features-logging:${cxfVersion}"
compile "org.apache.commons:commons-lang3:${commonLang3Version}"
compileOnly('org.projectlombok:lombok')
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("oracle:ojdbc6:11.2.0.3")
compile project(':my-generator')
testCompile 'org.springframework.boot:spring-boot-starter-test'
}

我的生成器模块只是包含一些类的模块。

但我想把所有库的版本移到根渐变文件中。我在maven项目中做到了,我需要这样的东西:

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring.ws.version>3.0.0.RELEASE</spring.ws.version>
<jvnet.jaxb2.maven2.version>0.13.2</jvnet.jaxb2.maven2.version>
<cxf.version>3.2.4</cxf.version>
<commons.codec.version>1.11</commons.codec.version>
<springfox.version>2.7.0</springfox.version>
<oracle.version>11.2.0.3</oracle.version>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.0.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

但我不知道我怎么能用gradle做这个。

假设你的my generator项目是一个gradle项目,那么你可以在根构建中完成。gradle:

...
project(':my-server') {
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
....
}
project(':my-generator') {
apply plugin: 'java'
dependencies {
compile 'org.springframework.boot:spring-boot-dependencies:2.0.2.RELEASE'
}
}
...

使用"project"子句,可以仅将配置应用于根项目中的子模块项目。

使用"allprojects"子句,您可以将某些配置应用于所有子模块项目:

allprojects {
dependencies { ... }
}

看看这个https://www.petrikainulainen.net/programming/gradle/getting-started-with-gradle-creating-a-multi-project-build/

希望这能帮助

最新更新