Gradle+SpringBoot多模块开发

news/2024/11/28 15:40:04/

关于使用Gradle结合SpringBoot进行多模块开发。
本来是打算使用buildSrc之类的,但是感觉好像好麻烦,使用这种方法就可以实现,没必要采用其他的。
我不怎么会表述,可能写的跟粑粑一样,哈哈哈哈
这是我的项目地址。
存在gitee,会一直更新
TinaSprout
首先这是模块的目录结构

C:\USERS\MI\CODESPACE\IDEAPROJECTS\TINASPROUT.gitignore
│  build.gradle
│  gradlew
│  gradlew.bat
│  LICENSE
│  settings.gradle
│
├─.gradle
│  ├─7.6.1
│  │  │  gc.properties
│  │  │
│  │  ├─checksums
│  │  │      checksums.lock
│  │  │      md5-checksums.bin
│  │  │      sha1-checksums.bin
│  │  │
│  │  ├─dependencies-accessors
│  │  │      dependencies-accessors.lock
│  │  │      gc.properties
│  │  │
│  │  ├─executionHistory
│  │  │      executionHistory.bin
│  │  │      executionHistory.lock
│  │  │
│  │  ├─fileChanges
│  │  │      last-build.bin
│  │  │
│  │  ├─fileHashes
│  │  │      fileHashes.bin
│  │  │      fileHashes.lock
│  │  │      resourceHashesCache.bin
│  │  │
│  │  └─vcsMetadata
│  ├─buildOutputCleanup
│  │      buildOutputCleanup.lock
│  │      cache.properties
│  │      outputFiles.bin
│  │
│  └─vcs-1
│          gc.properties
│
├─.idea
│  │  compiler.xml
│  │  git_toolbox_prj.xml
│  │  gradle.xml
│  │  jarRepositories.xml
│  │  misc.xml
│  │  modules.xml
│  │  vcs.xml
│  │  workspace.xml
│  │
│  └─modules
│      ├─tinasprout-core
│      │      TinaSprout.tinasprout-core.main.iml
│      │
│      └─tinasprout-robot
│              TinaSprout.tinasprout-robot.main.iml
│
├─gradle
│  └─wrapper
│          gradle-wrapper.jar
│          gradle-wrapper.properties
│
├─tinasprout-core
│  │  .gitignore
│  │  build.gradle
│  │  gradlew
│  │  gradlew.bat
│  │
│  ├─gradle
│  │  └─wrapper
│  │          gradle-wrapper.jar
│  │          gradle-wrapper.properties
│  │
│  └─src
│      ├─main
│      │  ├─java
│      │  │  └─com
│      │  │      └─wuxianggujun
│      │  │          └─tinasproutcore
│      │  │              │  TinaSproutCoreApplication.java
│      │  │              │
│      │  │              ├─config
│      │  │              │      BotConfig.java
│      │  │              │
│      │  │              └─network
│      │  │                      WsHandler.java
│      │  │
│      │  └─resources
│      │      │  application.properties
│      │      │
│      │      ├─static
│      │      └─templates
│      └─test
│          └─java
│              └─com
│                  └─wuxianggujun
│                      └─tinasproutcore
│                              TinaSproutCoreApplicationTests.java
│
└─tinasprout-robot│  .gitignore│  build.gradle│  gradlew│  gradlew.bat│├─gradle│  └─wrapper│          gradle-wrapper.jar│          gradle-wrapper.properties│└─src├─main│  ├─java│  │  └─com│  │      └─wuxianggujun│  │          └─tinasproutrobot│  │                  TinasproutRobotApplication.java│  ││  └─resources│      │  application.properties│      ││      ├─static│      └─templates└─test└─java└─com└─wuxianggujun└─tinasproutrobotTinasproutRobotApplicationTests.java

步骤就是,现在创建一个Gradle项目,取名为TinaSprout(当然,这是我项目的名字,你们随便取)然后删除src的目录,用不到。
然后新建两个子模块tinasprout-coretinasprout-robot
tinasprout-core ----- 是用来写核心框架的。
tinasprout-robot -----是SpringBoot启动项目。
将两个子模块的settings.gradle删除,不需要。
完成之后开始编写我们根目录的settings.gradle文件,将两个子模块引入。

rootProject.name = 'TinaSprout'
include 'tinasprout-core'
include 'tinasprout-robot'

现在我们开始编写根目录的build.gradle,用于管理子模块

buildscript {repositories {mavenLocal()maven {url 'https://repo.huaweicloud.com/repository/maven/'}}dependencies {classpath("org.springframework.boot:spring-boot-gradle-plugin:3.0.4")}
}plugins {id 'java'id 'org.springframework.boot' version '3.0.4' apply false//apply false的作用是告诉Gradle不要执行插件的逻辑,只是声明依赖id 'io.spring.dependency-management' version '1.1.0'
}allprojects {apply plugin: 'java'group 'com.wuxianggujun'version '1.0-SNAPSHOT'sourceCompatibility = '17'configurations {compileOnly {extendsFrom annotationProcessor}}repositories {mavenCentral()maven {url 'https://repo.huaweicloud.com/repository/maven/'}}dependencies {testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'}tasks.withType(JavaCompile) {options.encoding = "UTF-8"}}subprojects {apply plugin: 'org.springframework.boot'apply plugin: 'io.spring.dependency-management'dependencyManagement {imports {mavenBom "org.springframework.boot:spring-boot-dependencies:3.0.4"}}dependencies {implementation 'org.springframework.boot:spring-boot-starter'implementation 'org.springframework.boot:spring-boot-starter-web'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'}tasks.named('test') {useJUnitPlatform()}}

通过上面的build.gradle配置文件,设置了allprojects和subprojects用于定义一些共用的内容。反正不难,应该看得懂吧!
接下来是tinasprout-core,我是想将这个打包成jar包,供给tinasprout-robot使用。所以指定bootjar的enabled为false,jar 的enabled为true

bootJar{enabled(false)archiveBaseName = 'tinasprout-core'archiveVersion = '0.0.1-SNAPSHOT'
}jar{enabled = true
}dependencies {implementation "com.alibaba:fastjson:1.2.83"implementation 'io.netty:netty-all:4.1.86.Final'
}

接下来,我们看tinasprout-robot的配置文件,这是用于部署在服务器启动SpringBoot的。

springBoot {mainClass = 'com.wuxianggujun.tinasproutrobot.TinasproutRobotApplication'
}bootJar {archiveBaseName = 'TinaSprout'archiveVersion = '0.0.1-SNAPSHOT'// 将子模块一起打包进来includeEmptyDirs = true// 设置输出目录,相对于项目根目录destinationDirectory = file("$rootDir/build")
}dependencies {implementation project(':tinasprout-core')
}

指定springBoot的mainClass,用于在jar启动的时候可以运行springboot。
bootJar的一些属性,是我自己假的,当然你们也可以删除,不影响。
我是要添加这些是要将这个jar包,部署在服务器,所以修改名称输出在根目录的build文件下。
在这里插入图片描述
通过运行bootjar将SpringBoot项目打包成jar包,我们就可以在build目录中看见。
在这里插入图片描述
现在项目模块化已经完成了,我也不知道应该搞什么。直接来运行看看效果吧。
打开终端,将文件夹拖动到当前目录,我们使用命令来查看一下jar包。
在这里插入图片描述
使用这条命令查看,这个命令用于查看一个 JAR 文件中包含的所有文件和目录,可以用来确认 JAR 文件中是否包含了需要的类和资源文件。

jar tf .\TinaSprout-0.0.1-SNAPSHOT.jar //其他命令
jar tf <jar包> | grep 'BOOT-INF/lib' 
jar tf <jar包> | grep 'BOOT-INF/classes'

在这里插入图片描述
这是输出内容,可以看到tinasprout-core-1.0-SNAPSHOT-plain已经被打包进去了。

META-INF/
META-INF/MANIFEST.MF
org/
org/springframework/
org/springframework/boot/
org/springframework/boot/loader/
org/springframework/boot/loader/ClassPathIndexFile.class
org/springframework/boot/loader/ExecutableArchiveLauncher.class
org/springframework/boot/loader/JarLauncher.class
org/springframework/boot/loader/LaunchedURLClassLoader$DefinePackageCallType.class
org/springframework/boot/loader/LaunchedURLClassLoader$UseFastConnectionExceptionsEnumeration.class
org/springframework/boot/loader/LaunchedURLClassLoader.class
org/springframework/boot/loader/Launcher.class
org/springframework/boot/loader/MainMethodRunner.class
org/springframework/boot/loader/PropertiesLauncher$ArchiveEntryFilter.class
org/springframework/boot/loader/PropertiesLauncher$ClassPathArchives.class
org/springframework/boot/loader/PropertiesLauncher$PrefixMatchingArchiveFilter.class
org/springframework/boot/loader/PropertiesLauncher.class
org/springframework/boot/loader/WarLauncher.class
org/springframework/boot/loader/archive/
org/springframework/boot/loader/archive/Archive$Entry.class
org/springframework/boot/loader/archive/Archive$EntryFilter.class
org/springframework/boot/loader/archive/Archive.class
org/springframework/boot/loader/archive/ExplodedArchive$AbstractIterator.class
org/springframework/boot/loader/archive/ExplodedArchive$ArchiveIterator.class
org/springframework/boot/loader/archive/ExplodedArchive$EntryIterator.class
org/springframework/boot/loader/archive/ExplodedArchive$FileEntry.class
org/springframework/boot/loader/archive/ExplodedArchive$SimpleJarFileArchive.class
org/springframework/boot/loader/archive/ExplodedArchive.class
org/springframework/boot/loader/archive/JarFileArchive$AbstractIterator.class
org/springframework/boot/loader/archive/JarFileArchive$EntryIterator.class
org/springframework/boot/loader/archive/JarFileArchive$JarFileEntry.class
org/springframework/boot/loader/archive/JarFileArchive$NestedArchiveIterator.class
org/springframework/boot/loader/archive/JarFileArchive.class
org/springframework/boot/loader/data/
org/springframework/boot/loader/data/RandomAccessData.class
org/springframework/boot/loader/data/RandomAccessDataFile$DataInputStream.class
org/springframework/boot/loader/data/RandomAccessDataFile$FileAccess.class
org/springframework/boot/loader/data/RandomAccessDataFile.class
org/springframework/boot/loader/jar/
org/springframework/boot/loader/jar/AbstractJarFile$JarFileType.class
org/springframework/boot/loader/jar/AbstractJarFile.class
org/springframework/boot/loader/jar/AsciiBytes.class
org/springframework/boot/loader/jar/Bytes.class
org/springframework/boot/loader/jar/CentralDirectoryEndRecord$Zip64End.class
org/springframework/boot/loader/jar/CentralDirectoryEndRecord$Zip64Locator.class
org/springframework/boot/loader/jar/CentralDirectoryEndRecord.class
org/springframework/boot/loader/jar/CentralDirectoryFileHeader.class
org/springframework/boot/loader/jar/CentralDirectoryParser.class
org/springframework/boot/loader/jar/CentralDirectoryVisitor.class
org/springframework/boot/loader/jar/FileHeader.class
org/springframework/boot/loader/jar/Handler.class
org/springframework/boot/loader/jar/JarEntry.class
org/springframework/boot/loader/jar/JarEntryCertification.class
org/springframework/boot/loader/jar/JarEntryFilter.class
org/springframework/boot/loader/jar/JarFile$1.class
org/springframework/boot/loader/jar/JarFile$JarEntryEnumeration.class
org/springframework/boot/loader/jar/JarFile.class
org/springframework/boot/loader/jar/JarFileEntries$1.class
org/springframework/boot/loader/jar/JarFileEntries$EntryIterator.class
org/springframework/boot/loader/jar/JarFileEntries$Offsets.class
org/springframework/boot/loader/jar/JarFileEntries$Zip64Offsets.class
org/springframework/boot/loader/jar/JarFileEntries$ZipOffsets.class
org/springframework/boot/loader/jar/JarFileEntries.class
org/springframework/boot/loader/jar/JarFileWrapper.class
org/springframework/boot/loader/jar/JarURLConnection$1.class
org/springframework/boot/loader/jar/JarURLConnection$JarEntryName.class
org/springframework/boot/loader/jar/JarURLConnection.class
org/springframework/boot/loader/jar/StringSequence.class
org/springframework/boot/loader/jar/ZipInflaterInputStream.class
org/springframework/boot/loader/jarmode/
org/springframework/boot/loader/jarmode/JarMode.class
org/springframework/boot/loader/jarmode/JarModeLauncher.class
org/springframework/boot/loader/jarmode/TestJarMode.class
org/springframework/boot/loader/util/
org/springframework/boot/loader/util/SystemPropertyUtils.class
BOOT-INF/
BOOT-INF/classes/
BOOT-INF/classes/com/
BOOT-INF/classes/com/wuxianggujun/
BOOT-INF/classes/com/wuxianggujun/tinasproutrobot/
BOOT-INF/classes/com/wuxianggujun/tinasproutrobot/TinasproutRobotApplication.class
BOOT-INF/classes/application.properties
BOOT-INF/lib/
BOOT-INF/lib/tinasprout-core-1.0-SNAPSHOT-plain.jar
BOOT-INF/lib/spring-boot-autoconfigure-3.0.4.jar
BOOT-INF/lib/spring-boot-3.0.4.jar
BOOT-INF/lib/jakarta.annotation-api-2.1.1.jar
BOOT-INF/lib/spring-webmvc-6.0.6.jar
BOOT-INF/lib/spring-web-6.0.6.jar
BOOT-INF/lib/spring-context-6.0.6.jar
BOOT-INF/lib/spring-aop-6.0.6.jar
BOOT-INF/lib/spring-beans-6.0.6.jar
BOOT-INF/lib/spring-expression-6.0.6.jar
BOOT-INF/lib/spring-core-6.0.6.jar
BOOT-INF/lib/snakeyaml-1.33.jar
BOOT-INF/lib/fastjson-1.2.83.jar
BOOT-INF/lib/netty-all-4.1.89.Final.jar
BOOT-INF/lib/logback-classic-1.4.5.jar
BOOT-INF/lib/log4j-to-slf4j-2.19.0.jar
BOOT-INF/lib/jul-to-slf4j-2.0.6.jar
BOOT-INF/lib/spring-jcl-6.0.6.jar
BOOT-INF/lib/jackson-datatype-jsr310-2.14.2.jar
BOOT-INF/lib/jackson-module-parameter-names-2.14.2.jar
BOOT-INF/lib/jackson-annotations-2.14.2.jar
BOOT-INF/lib/jackson-core-2.14.2.jar
BOOT-INF/lib/jackson-datatype-jdk8-2.14.2.jar
BOOT-INF/lib/jackson-databind-2.14.2.jar
BOOT-INF/lib/tomcat-embed-websocket-10.1.5.jar
BOOT-INF/lib/tomcat-embed-core-10.1.5.jar
BOOT-INF/lib/tomcat-embed-el-10.1.5.jar
BOOT-INF/lib/micrometer-observation-1.10.4.jar
BOOT-INF/lib/netty-transport-native-epoll-4.1.89.Final-linux-x86_64.jar
BOOT-INF/lib/netty-transport-native-epoll-4.1.89.Final-linux-aarch_64.jar
BOOT-INF/lib/netty-transport-native-kqueue-4.1.89.Final-osx-x86_64.jar
BOOT-INF/lib/netty-transport-native-kqueue-4.1.89.Final-osx-aarch_64.jar
BOOT-INF/lib/netty-transport-classes-epoll-4.1.89.Final.jar
BOOT-INF/lib/netty-transport-classes-kqueue-4.1.89.Final.jar
BOOT-INF/lib/netty-resolver-dns-native-macos-4.1.89.Final-osx-x86_64.jar
BOOT-INF/lib/netty-resolver-dns-native-macos-4.1.89.Final-osx-aarch_64.jar
BOOT-INF/lib/netty-resolver-dns-classes-macos-4.1.89.Final.jar
BOOT-INF/lib/netty-resolver-dns-4.1.89.Final.jar
BOOT-INF/lib/netty-handler-4.1.89.Final.jar
BOOT-INF/lib/netty-transport-native-unix-common-4.1.89.Final.jar
BOOT-INF/lib/netty-codec-dns-4.1.89.Final.jar
BOOT-INF/lib/netty-codec-4.1.89.Final.jar
BOOT-INF/lib/netty-transport-4.1.89.Final.jar
BOOT-INF/lib/netty-buffer-4.1.89.Final.jar
BOOT-INF/lib/netty-codec-haproxy-4.1.89.Final.jar
BOOT-INF/lib/netty-codec-http-4.1.89.Final.jar
BOOT-INF/lib/netty-codec-http2-4.1.89.Final.jar
BOOT-INF/lib/netty-codec-memcache-4.1.89.Final.jar
BOOT-INF/lib/netty-codec-mqtt-4.1.89.Final.jar
BOOT-INF/lib/netty-codec-redis-4.1.89.Final.jar
BOOT-INF/lib/netty-codec-smtp-4.1.89.Final.jar
BOOT-INF/lib/netty-codec-socks-4.1.89.Final.jar
BOOT-INF/lib/netty-codec-stomp-4.1.89.Final.jar
BOOT-INF/lib/netty-codec-xml-4.1.89.Final.jar
BOOT-INF/lib/netty-resolver-4.1.89.Final.jar
BOOT-INF/lib/netty-common-4.1.89.Final.jar
BOOT-INF/lib/netty-handler-proxy-4.1.89.Final.jar
BOOT-INF/lib/netty-handler-ssl-ocsp-4.1.89.Final.jar
BOOT-INF/lib/netty-transport-rxtx-4.1.89.Final.jar
BOOT-INF/lib/netty-transport-sctp-4.1.89.Final.jar
BOOT-INF/lib/netty-transport-udt-4.1.89.Final.jar
BOOT-INF/lib/logback-core-1.4.5.jar
BOOT-INF/lib/slf4j-api-2.0.6.jar
BOOT-INF/lib/log4j-api-2.19.0.jar
BOOT-INF/lib/micrometer-commons-1.10.4.jar
BOOT-INF/classes/static/
BOOT-INF/classes/templates/
BOOT-INF/lib/spring-boot-jarmode-layertools-3.0.4.jar
BOOT-INF/classpath.idx
BOOT-INF/layers.idx

接下来,运行看看

java -jar .\TinaSprout-0.0.1-SNAPSHOT.jar 

在这里插入图片描述
输入命令之后可以看到。项目已经成功的被启动了。
在这里插入图片描述


http://www.ppmy.cn/news/30419.html

相关文章

蓝桥杯C/C++程序设计 往届真题汇总(进阶篇)

文章目录1. 最短路2. 数字三角形3. 递增序列4. 杨辉三角形5. 跳跃6. 路径7. 迷宫8. 装饰珠9. 明码10. 字串分值11. 作物杂交12. 承压计算13. 全球变暖14. 直线15. 平面切分1. 最短路 题目描述&#xff1a; 如下图所示&#xff0c;G是一个无向图&#xff0c;其中蓝色边的长度是…

vue种env配置以及在路由中的简单使用

env是什么&#xff1f;.env文件是vue运行项目时的环境配置文件&#xff0c;它可以存储不同环境下的变量。.env文件与src目录并列&#xff0c;.env&#xff1a;全局默认配置文件&#xff0c;无论什么环境都会加载合并。.env.development&#xff1a;开发环境的配置文件.env.prod…

八股文(四)

目录 一、 Vue2的双向数据绑定原理 二、 vue2数据绑定缺点是什么&#xff1f;vue3是怎么解决的&#xff1f; &#xff08;1&#xff09;因为vue2.0 object.defineProperty只能劫持对象属性 &#xff08;2&#xff09;Proxy是直接代理对象 &#xff08;3&#xff09;proxy不…

基于Python的selenium

一、安装 1.1安装Python&#xff0c;安装Python时需要勾选增加环境变量 如果之前已经安装过Python&#xff0c;需要将Python相关文件以及环境变量删除 1.2安装成功&#xff1a;在命令行界面下输入Python&#xff0c;最终展示>>>即可成功 2.1安装pycharm,直接自定义安装…

【Vue】vue中的mixin混入

Vue中的mixin混入 文章目录Vue中的mixin混入简介功能mixin存在的问题混入特性总结部分特性详解定义混入使用混入两种方法组件和混入对象含有同名选项时&#xff0c;这些选项将以恰当的方式进行“合并”&#xff0c;在发生冲突时以组件优先。同名生命周期钩子将合并为一个数组&a…

世界那么大,你哪都别去了,来我带你了解CSS3 (二)

文章目录‍❤️‍&#x1f525;CSS文档流‍❤️‍&#x1f525;CSS浮动‍❤️‍&#x1f525;CSS定位‍❤️‍&#x1f525;CSS媒体查询‍❤️‍&#x1f525;CSS文档流 文档流是文档中可显示对象在排列时所占用的位置/空间。 例如&#xff1a;块元素自上而下摆放&#xff0c;内…

K_A16_001 基于STM32等单片机驱动HX711称重模块 串口与OLED0.96双显示

K_A16_001 基于STM32等单片机驱动HX711称重模块 串口与OLED0.96双显示一、资源说明二、基本参数参数引脚说明三、驱动说明对应程序:四、部分代码说明1、接线引脚定义1.1、STC89C52RCHX711称重模块1.2、STM32F103C8T6HX711称重模块五、基础知识学习与相关资料下载六、视频效果展…

Java之可变参数

目录 一.可变参数的引入 1.问题引入 2.可变参数的使用 二.可变参数的注意点 1.可变参数只能定义一个 2.可变参数必须是函数参数的最后一个​编辑 一.可变参数的引入 1.问题引入 当我们需要定义一个方法sum,接受任意个整型变量,结果返回这些整型变量的和. 我们没有学习可…