How to build a SpringBoot multi-module project in Gradle
This article introduces how to build a SpringBoot multi-module project in Gradle, the content is very detailed, interested friends can refer to, hope to be helpful to you.
1. Settings.gradle
/ * rootProject.name project name * include module name * / rootProject.name = 'micro-service-framework'include' framework-base'include 'framework-web'include' framework-redis'
2. Build.gradle
This is equivalent to the parent maven configuration in maven
Buildscript {ext {/ / spring boot version bootVersion = '2.0.6.RELEASE'} / / Private server address, which is applicable to gradle itself, such as deletion The following springboot plug-in will not find the repositories {maven {url 'http://maven.aliyun.com/nexus/content/groups/public/'}} / / springboot gradle plug-in configuration dependencies {classpath ("org.springframework.boot:spring-boot-gradle-plugin:$ {bootVersion}")}} allprojects {/ / plug-in apply plugin:' java' apply plugin: 'maven' / / if the plug-in is imported You need to specify main class, otherwise you cannot package / / apply plugin: 'org.springframework.boot' apply plugin:' io.spring.dependency-management' / / this plug-in is used to publish the jar package to the private server apply plugin: 'maven-publish' / / jdk compiled version sourceCompatibility = 1.8 / / jar package group, version configuration group' net.178le.micro' version '0.0.1 version SNAPSHOT' / / private server address Repositories {maven {url 'http://maven.aliyun.com/nexus/content/groups/public/'}} / * imports the pom file of springboot,spring cloud, eliminating the need to manage your own version * PS: there is another configuration on the official website of Spring, which requires configuration of main class. Explain in a moment that * / dependencyManagement {imports {mavenBom "org.springframework.boot:spring-boot-starter-parent:$ {bootVersion}" mavenBom "org.springframework.cloud:spring-cloud-dependencies:Finchley.SR2"}} / / publish configuration publishing {publications {maven (MavenPublication) {/ / specify group/artifact/version information You don't have to fill it out. By default, the project group/name/version is used as groupId/artifactId/version groupId = project.group artifactId = project.name version = project.version / / if it is a war package, fill in components.web If it is a jar package, fill in components.java from components.java / / configure the upload source code artifact sourceJar {classifier "src"} repositories {maven {def releasesUrl = "http:// your private server ip:8081 / repository/maven-releases/ "def snapshotsUrl =" http:// your private service ip:8081/repository/maven-snapshots/ "url = version.endsWith ('SNAPSHOT')? SnapshotsUrl: releasesUrl credentials {username = 'admin' password =' admin123'} / / the configuration here takes effect on the subproject subprojects {dependencies {testCompile ("org.springframework.boot:spring-boot-starter-test") compile ("com.google.guava") : guava:28.0-jre ")}} / / package source code task sourceJar (type: Jar) {from sourceSets.main.allJava}
Maven publish usage
There are several commands in task-> publishing
I think it is enough to use these two commands
PublishMavenPublicationToMavenLocal publishes the project to the local warehouse
PublishMavenPublicationToMavenRepository publishes projects to private servers
PS: using apply plugin: 'org.springframework.boot' build must specify main class
23:26:17: Executing task 'build'... > Task: framework-base:compileJava NO-SOURCE > Task: framework-base:processResources NO-SOURCE > Task: framework-base:classes UP-TO-DATE > Task: framework-base:jar SKIPPED > Task: framework-redis:compileJava UP-TO-DATE > Task > Task: framework-redis:classes UP-TO-DATE > Task: framework-redis:jar SKIPPED > Task: framework-web:compileJava UP-TO-DATE > Task: framework-web:processResources NO-SOURCE > Task : framework-web:classes UP-TO-DATE > Task: framework-web:bootJar FAILEDFAILURE: Build failed with an exception.* What went wrong:Execution failed for task': framework-web:bootJar'. > Main class name has not been configured and it could not be resolved* Try:Run with-- stacktrace option to get the stack trace. Run with-info or-debug option to get more log output. Run with-- scan to get full insights.* Get more help at https://help.gradle.orgDeprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.Use'--warning-mode all' to show the individual deprecation warnings.See https://docs.gradle.org/4.10.3/userguide/command_line_interface.html#sec:command_line_warningsBUILD FAILED in 1s3 actionable tasks: 1 executed, 2 up-to-dateMain class name has not been configured and it could not be resolved23:26:18: Task execution finished 'build'.
Framework-web Project 3. Build.gradle
Dependencies {/ / dependent framework-redis project compile project (': framework-redis') / / do not need to write version compile ('org.springframework.boot:spring-boot-starter-web') / / do not need to write version compile (' org.springframework.cloud:spring-cloud-starter-openfeign')}
Framework-redis Project 4. Build.gradle
Dependencies {/ / depends on framework-base compile project (': framework-base') compile ('org.springframework.boot:spring-boot-starter-data-redis')}
Framework-base 5. Build.gradle
/ / as a demonstration, I have not introduced any jar package dependencies {} to share here on how to build a SpringBoot multi-module project in Gradle. I hope the above content can be helpful to everyone and learn more knowledge. If you think the article is good, you can share it for more people to see.