安装 tree 后 执行 tree -f . > tr.txt 可以生产下面的代码结构 ├── ./api-test │ ├── ./api-test/build.gradle │ └── ./api-test/src │ └── ./api-test/src/main │ └── ./api-test/src/main/java ├── ./build.gradle ├── ./gradle │ └── ./gradle/wrapper │ ├── ./gradle/wrapper/gradle-wrapper.jar │ └── ./gradle/wrapper/gradle-wrapper.properties ├── ./gradlew ├── ./gradlew.bat ├── ./settings.gradle 这是最基本的多模块模式 gradle-wrapper.properties 可以配置国内的镜像地址 distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-7.3.2-bin.zip
settings.gradle 记录的是项目及模块
父类的build.gradle 记录了最基本的 引用插件-plugins 依赖包来源-repositories 依赖包配置- dependencies (公共依赖包可以定在这里)
//buildscript中的ext用于定义框架的版本 buildscript { ext { springBootVersion = "2.6.13" springCloudVersion = "2021.0.5" springCloudAlibabaVersion = "2021.0.5.0" } } /** * 兼容版本 * springboot 2.6.*或者2.7.* * springCloud 2021.0.5 * springCloudAlibaba 2021.0.5.0 * nacos 2.2.0 */ // 插件 plugins { id "java" // 有这个声明,子模块可以使用org.springframework.boot插件而无需指定版本,但是apply=false表示当前模块不使用此插件 id "org.springframework.boot" version "${springBootVersion}" apply false id "io.spring.dependency-management" version "1.0.11.RELEASE" } //定义依赖源 allprojects { group = "zt" version = "1.0-SNAPSHOT" // 仓库 repositories { mavenLocal() maven { setUrl("https://maven.aliyun.com/repository/public/") } maven { setUrl("https://公司/nexus/content/groups/public/") } mavenCentral() } } //子模块配置 subprojects { apply plugin: "org.springframework.boot" //使用springboot插件 apply plugin: "io.spring.dependency-management" //版本管理插件 apply plugin: "java" sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 // java编译的时候缺省状态下会因为中文字符而失败 [compileJava, compileTestJava, javadoc]*.options*.encoding = "UTF-8" // 配置所有子模块的依赖仓库地址 bootJar { archiveBaseName = "dist" archiveVersion = "" } // 依赖管理 dependencyManagement { imports { mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootVersion}" mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" // mavenBom "com.alibaba.cloud:spring-cloud-alibaba-dependencies:${springCloudAlibabaVersion}" } } //默认应用依赖 dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-test' implementation 'org.springframework.boot:spring-boot-starter-data-redis' implementation 'org.springframework.boot:spring-boot-starter-jdbc' implementation "org.springframework.cloud:spring-cloud-starter-bootstrap" implementation "com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-config:${springCloudAlibabaVersion}" implementation "com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery:${springCloudAlibabaVersion}" annotationProcessor 'org.projectlombok:lombok:1.18.20' } }
子模块的 build.gradle
// 配置service模块 plugins { id 'java-library' } dependencies { // 定义依赖项 implementation 'org.projectlombok:lombok:1.18.20' implementation project(':api') }
标签:spring,boot,springframework,gradle,模块,org,Gradle,cloud From: https://www.cnblogs.com/long-yuan/p/18547798