Gradle中怎么构建一个SpringBoot多模块项目
发表于:2025-12-01 作者:千家信息网编辑
千家信息网最后更新 2025年12月01日,这篇文章给大家介绍Gradle中怎么构建一个SpringBoot多模块项目,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。1. settings.gradle/** * rootP
千家信息网最后更新 2025年12月01日Gradle中怎么构建一个SpringBoot多模块项目
这篇文章给大家介绍Gradle中怎么构建一个SpringBoot多模块项目,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
1. settings.gradle
/** * rootProject.name 项目名称 * include 模块名称 */rootProject.name = 'micro-service-framework'include 'framework-base'include 'framework-web'include 'framework-redis'
2. build.gradle
这个相当于maven中的父maven配置
buildscript { ext { //spring boot 版本 bootVersion = '2.0.6.RELEASE' } //私服地址,这个地址适用于gradle自身,比如删除,下面的springboot插件就会找不到 repositories { maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } } //springboot gradle插件配置 dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${bootVersion}") }}allprojects { //导入使用的插件 apply plugin: 'java' apply plugin: 'maven' //如果导入该插件,你需要指定main class,否则不能打包 //apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' //这个插件用于发布jar包到私服 apply plugin: 'maven-publish' //jdk编译版本 sourceCompatibility = 1.8 //jar包的group ,version配置 group 'net.178le.micro' version '0.0.1-SNAPSHOT' //私服地址, repositories { maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } } /** * 导入了springboot,spring cloud的pom文件,能够免去自己管理版本 * PS: 在Spring官网指导上面有另外一种配置,那种配置需要配置main class,一会说明 */ dependencyManagement { imports { mavenBom "org.springframework.boot:spring-boot-starter-parent:${bootVersion}" mavenBom "org.springframework.cloud:spring-cloud-dependencies:Finchley.SR2" } } //私服发布配置 publishing { publications { maven(MavenPublication) { //指定group/artifact/version信息,可以不填。默认使用项目group/name/version作为groupId/artifactId/version groupId = project.group artifactId = project.name version = project.version //如果是war包填写components.web,如果是jar包填写components.java from components.java //配置上传源码 artifact sourceJar { classifier "src" } } } repositories { maven { def releasesUrl = "http://你的私服ip:8081/repository/maven-releases/" def snapshotsUrl = "http://你的私服ip:8081/repository/maven-snapshots/" url = version.endsWith('SNAPSHOT') ? snapshotsUrl : releasesUrl credentials { username = 'admin' password = 'admin123' } } } }}//这里的配置对子项目生效subprojects { dependencies { testCompile("org.springframework.boot:spring-boot-starter-test") compile("com.google.guava:guava:28.0-jre") }}//打包源码task sourceJar(type: Jar) { from sourceSets.main.allJava}maven publish使用
在task -> publishing 中有如下几个命令
我认为使用这两个命令就足够了
publishMavenPublicationToMavenLocal 发布项目到本地仓库
publishMavenPublicationToMavenRepository 发布项目到私服
PS:使用apply plugin: 'org.springframework.boot' build必须要指定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 :framework-redis:processResources NO-SOURCE> 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 项目 3. build.gradle
dependencies { //依赖framework-redis项目 compile project(':framework-redis') //不需要写版本 compile('org.springframework.boot:spring-boot-starter-web') //不需要写版本 compile('org.springframework.cloud:spring-cloud-starter-openfeign')}framework-redis 项目 4. build.gradle
dependencies { //依赖framework-base compile project(':framework-base') compile('org.springframework.boot:spring-boot-starter-data-redis')}framework-base 5. build.gradle
//做为演示没有引入任何jar包dependencies {}关于Gradle中怎么构建一个SpringBoot多模块项目就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
项目
配置
私服
插件
版本
模块
地址
内容
名称
命令
更多
源码
帮助
不错
两个
仓库
信息
兴趣
对子
小伙
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
达梦数据库设计说明书
福建诚信网络技术服务哪家好
用单例模式处理共享数据库
软件开发模型怎么写
有独立软件开发的金融公司
html 获取服务器数据
国内最有名社交软件开发公司
多措并举保护青少年网络安全
如何做一个数据库订单
数据库控件浏览按键在哪
方舟生存进化服务器管理器
温州软件开发多少钱
广西南宁网络技术公司招聘
如何查看服务器是否安装yum
系统融合软件开发部
设置 js 不缓存数据库
怎么改扫号数据库
网络产品服务器
二道区智能化网络技术质量服务
sql2000数据库恢复
七日杀服务器怎么安装
南京商邻互联网科技有限责任
国网公司的网络安全
关系数据库中子模式称为
客户端直连数据库安全吗
客多多软件开发商电话
软件开发费用抵扣税率
甘肃便民平台软件开发电话
服务器端口安全管理
随着5g网络技术的发展市场