IDEA 2020.2 +Gradle 6.6.1 + Spring Boot 2.3.4 創(chuàng)建多模塊項(xiàng)目的超詳細(xì)教程
環(huán)境介紹 IDEA
我用的是2020.2
Gradle
安裝參考 Gradle安裝配置
我這安裝的是6.6.1
C:\Users\herion>gradle -v ------------------------------------------------------------ Gradle 6.6.1 ------------------------------------------------------------ Build time: 2020-08-25 16:29:12 UTC Revision: f2d1fb54a951d8b11d25748e4711bec8d128d7e3 Kotlin: 1.3.72 Groovy: 2.5.12 Ant: Apache Ant(TM) version 1.10.8 compiled on May 10 2020 JVM: 1.8.0_211 (Oracle Corporation 25.211-b12) OS: Windows 10 10.0 amd64
創(chuàng)建 gradle-parent New Project --> Spring Initalizr 選擇jdk版本,我這里使用1.8
Next
–> 根據(jù)需求修改 Group、Artifact、version 、Type、name、package 等,選擇所需依賴創(chuàng)建項(xiàng)目
創(chuàng)建成功后刪除src 目錄
創(chuàng)建子模塊 gradle-demo
選中g(shù)radle-parent–> new -->Module
創(chuàng)建子模塊操作與創(chuàng)建gradle-parent 雷同,這里就不做復(fù)述了,創(chuàng)建好gradle-demo后在gradle-parent的settings.gradle 中引入模塊依賴 include ‘gradle-demo'
刪除gradle-demo 中settings.gradle文件,否則不能喝gradle-parent建立依賴關(guān)系
定義gradle 自身所需資源
buildscript { ext { springBootVersion = '2.3.4.RELEASE' springBootManagementVersion = '1.0.8.RELEASE' springCloudVersion = 'Hoxton.SR6' REPOSITORY_HOME = "http://maven.aliyun.com" } repositories { maven { url '${REPOSITORY_HOME}/nexus/content/groups/public/' } mavenCentral() maven { url 'https://repo.spring.io/snapshot' } maven { url 'https://repo.spring.io/milestone' } } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") classpath("io.spring.gradle:dependency-management-plugin:${springBootManagementVersion}") } }
修改gradle-parent項(xiàng)目build.gradle 配置全項(xiàng)目通用配置
allprojects { apply plugin: 'java' apply plugin: 'idea' group = 'com.herion' sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 }
子項(xiàng)目通用配置
subprojects { apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' [compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8' //倉庫 repositories { maven { url '${REPOSITORY_HOME}/nexus/content/groups/public/' } mavenCentral() maven { url 'https://repo.spring.io/snapshot' } maven { url 'https://repo.spring.io/milestone' } } dependencies { implementation 'org.springframework.boot:spring-boot-starter' compileOnly 'org.projectlombok:lombok' developmentOnly 'org.springframework.boot:spring-boot-devtools' annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' annotationProcessor 'org.projectlombok:lombok' testImplementation('org.springframework.boot:spring-boot-starter-test') { exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' } } dependencyManagement { imports { mavenBom("org.springframework.boot:spring-boot-dependencies:${springBootVersion}") } imports { mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" } } test { useJUnitPlatform() } }
發(fā)布插件配置
/** * 發(fā)布插件 */ publishing { publications { mavenJava(MavenPublication) { from components.java versionMapping { usage('java-api') { fromResolutionOf('runtimeClasspath') } usage('java-runtime') { fromResolutionResult() } } } } // 發(fā)布倉庫 repositories { maven { // TODO 換成自己的私服地址 def releasesRepoUrl = "http://my.repo.com/nexus/repository/maven-releases" def snapshotsRepoUrl = "http://my.repo..com/nexus/repository/maven-snapshots" url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl credentials { username nexusUser password nexusPassword } } } } configurations { [apiElements, runtimeElements].each { it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(jar) } it.outgoing.artifact(bootJar) } }
驗(yàn)證
Gradle 查看所有項(xiàng)目
gradle projects > Task :projects ------------------------------------------------------------ Root project ------------------------------------------------------------ Root project 'gradle-parent' +--- Project ':gradle-common' +--- Project ':gradle-demo' \--- Project ':gradle-demo2' To see a list of the tasks of a project, run gradle <project-path>:tasks For example, try running gradle :gradle-common:tasks Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/6.6.1/userguide/command_line_interface.html#sec:command_line_warnings BUILD SUCCESSFUL in 4s 1 actionable task: 1 executed
編譯項(xiàng)目
$ gradle build Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/6.6.1/userguide/command_line_interface.html#sec:command_line_warnings BUILD SUCCESSFUL in 5s 12 actionable tasks: 12 up-to-date
執(zhí)行結(jié)果
發(fā)布jar包到nexus 命令
$ gradle publishMavenJavaPublicationToMavenRepository > Task :gradle-common:publishMavenJavaPublicationToMavenRepository > Task :gradle-demo:publishMavenJavaPublicationToMavenRepository > Task :gradle-demo2:publishMavenJavaPublicationToMavenRepository Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/6.6.1/userguide/command_line_interface.html#sec:command_line_warnings BUILD SUCCESSFUL in 24s 16 actionable tasks: 13 executed, 3 up-to-date
執(zhí)行結(jié)果
gradle-demo 驗(yàn)證 啟動(dòng)項(xiàng)目
瀏覽器訪問
http://localhost:8080/helllo?name=herion
到此這篇關(guān)于IDEA 2020.2 +Gradle 6.6.1 + Spring Boot 2.3.4 創(chuàng)建多模塊項(xiàng)目的文章就介紹到這了,更多相關(guān)idea+Gradle+springboot多模塊項(xiàng)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 如何使用IDEA2022.1?創(chuàng)建Spring?Boot項(xiàng)目
- IDEA教程創(chuàng)建SpringBoot前后端分離項(xiàng)目示例圖解
- IDEA創(chuàng)建SpringBoot的maven項(xiàng)目的方法步驟
- IDEA社區(qū)版創(chuàng)建spring boot項(xiàng)目的安裝插件的圖文教程
- idea創(chuàng)建springboot項(xiàng)目和springcloud項(xiàng)目的詳細(xì)教程
- IDEA2020.2創(chuàng)建springboot項(xiàng)目卡死在reading maven project的問題
- idea創(chuàng)建spring boot項(xiàng)目及java版本只能選擇17和21的問題
相關(guān)文章
mybaties?plus?selectMaps和selectList的區(qū)別說明
這篇文章主要介紹了mybaties?plus?selectMaps和selectList的區(qū)別說明,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-12-12Java Collection 移除元素方法及注意事項(xiàng)
這篇文章主要介紹了Java Collection 移除元素方法及注意事項(xiàng),通過一個(gè)簡單實(shí)例給大家講解,需要的朋友可以參考下2020-01-01Java基于Netty實(shí)現(xiàn)Http server的實(shí)戰(zhàn)
本文主要介紹了Java基于Netty實(shí)現(xiàn)Http server的實(shí)戰(zhàn),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02java web用servlet監(jiān)聽器實(shí)現(xiàn)顯示在線人數(shù)
這篇文章主要為大家詳細(xì)介紹了java web用servlet監(jiān)聽器實(shí)現(xiàn)顯示在線人數(shù),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-03-03