gpt4 book ai didi

java - 将所有库版本移动到多模块 gradle 项目中的根 gradle 文件

转载 作者:行者123 更新时间:2023-12-03 06:25:15 25 4
gpt4 key购买 nike

我有带有模块的 gradle 项目。

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

现在我的根项目的 gradle 文件如下所示:
    group = 'com.mayprojekt'
version = '0.0.1-SNAPSHOT'

Gradle 设置文件如下所示:
    rootProject.name = 'root-project'
include 'my-generator'
include 'my-server'

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'
}

my-generator 模块只是带有一些类的模块。

但我想将所有库版本移动到根 gradle 文件。我在 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 项目,那么您可以在根 build.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'
}
}

...

使用“项目”子句,您只能将配置应用于根项目中的子模块项目。

使用“allprojects”子句,您可以将某些配置应用于所有子模块项目:
allprojects {
dependencies { ... }
}

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

希望这可以帮助

关于java - 将所有库版本移动到多模块 gradle 项目中的根 gradle 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51595846/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com