标签:snap nts 3.1 connector XML student .class ldd put
一、在IDEA中使用工具创建SpringBoot + Gradle的父工程
new -> project -> Spring Initializr -> type选项选中Gradle Project(其他视情况填写)
父工程 : demo-springboot-gradle
二、在父工程下新建两个模块 web、dao
右键单击父工程 new -> module -> Spring Initializr -> type选项选中Gradle Project(其他视情况填写)
创建module的最后一步要注意,子模块最好在父工程的目录下,避免不必要的麻烦
三、删除dao子模块下的所有.java文件 、 删除父工程src文件
四、在dao子模块下创建两个类,用于测试Student 和 StudentService
-
-
-
-
-
-
-
-
-
-
public void setId(Integer id) {
-
-
-
-
public String getName() {
-
-
-
-
public void setName(String name) {
-
-
-
-
-
public class StudentService {
-
-
-
Student student = new Student();
-
-
-
-
-
-
五、在web子模块下创建一个接口类StudentController
-
-
public class StudentController {
-
-
-
private StudentService studentService;
-
-
-
-
return studentService.query();
-
-
六、dao子模块的bulid.gradle
-
-
-
-
-
-
sourceCompatibility = 1.8
-
-
-
-
-
-
-
testCompile group: ‘junit‘, name: ‘junit‘, version: ‘4.12‘
-
七、web子模块的bulid.gradle
-
-
-
springBootVersion = ‘1.5.3.RELEASE‘
-
-
-
-
-
-
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
-
-
-
-
-
-
apply plugin: ‘org.springframework.boot‘
-
-
-
version = ‘0.0.1-SNAPSHOT‘
-
sourceCompatibility = 1.8
-
-
-
-
-
-
-
-
-
-
-
compile(‘org.springframework.boot:spring-boot-starter-thymeleaf‘)
-
compile(‘org.springframework.boot:spring-boot-starter-web‘)
-
// providedRuntime(‘org.springframework.boot:spring-boot-starter-tomcat‘)
-
testCompile(‘org.springframework.boot:spring-boot-starter-test‘)
-
八、父工程bulid.gradle
-
-
-
-
-
sourceCompatibility = 1.8
-
targetCompatibility = 1.8
-
-
-
-
-
-
// slf4jVersion = ‘1.7.7‘
-
springVersion = ‘4.3.8.RELEASE‘
-
hibernateVersion = ‘4.3.1.Final‘
-
-
[compileJava, compileTestJava, javadoc]*.options*.encoding = ‘UTF-8‘
-
-
-
-
-
//compile.exclude module: ‘commons-logging‘
-
all*.exclude module: ‘commons-logging‘
-
-
-
-
‘redis.clients:jedis:2.9.0‘,
-
‘org.slf4j:slf4j-api:1.7.25‘,
-
‘ch.qos.logback:logback-core:1.1.11‘,
-
‘ch.qos.logback:logback-classic:1.1.11‘,
-
-
// "org.slf4j:jcl-over-slf4j:${slf4jVersion}",
-
// "org.slf4j:slf4j-log4j12:${slf4jVersion}",
-
"org.springframework:spring-context:$springVersion",
-
// "org.springframework:spring-orm:$springVersion",
-
// "org.springframework:spring-tx:$springVersion",
-
// "org.springframework.data:spring-data-jpa:1.5.2.RELEASE",
-
// "org.hibernate:hibernate-entitymanager:$hibernateVersion",
-
-
"mysql:mysql-connector-java:5.1.35",
-
// "commons-fileupload:commons-fileupload:1.3.1",
-
"com.fasterxml.jackson.core:jackson-databind:2.3.1"
-
-
-
"org.springframework:spring-test:$springVersion",
-
-
-
-
-
-
-
-
-
-
-
-
-
-
‘org.springframework.boot:spring-boot-starter-thymeleaf‘,
-
‘org.springframework.boot:spring-boot-starter-web‘
-
-
-
‘org.springframework.boot:spring-boot-starter-test‘
-
-
-
// "javax.servlet:javax.servlet-api:3.1.0",
-
// "javax.servlet.jsp:jsp-api:2.2.1-b03",
-
// "javax.servlet.jsp.jstl:javax.servlet.jsp.jstl-api:1.2.1"
-
-
-
-
/* 从‘$projectDir/src/main/java‘目录下复制文件到‘WEB-INF/classes‘目录下覆盖原有同名文件*/
-
from("$projectDir/src/main/java")
-
-
-
/*自定义任务用于将当前子项目的java类打成jar包,此jar包不包含resources下的文件*/
-
def jarArchiveName="${project.name}-${version}.jar"
-
task jarWithoutResources(type: Jar) {
-
from sourceSets.main.output.classesDir
-
archiveName jarArchiveName
-
-
-
-
-
dependsOn jarWithoutResources
-
/* classpath排除sourceSets.main.output.classesDir目录,加入jarWithoutResources打出来的jar包 */
-
classpath = classpath.minus(files(sourceSets.main.output.classesDir)).plus(files("$buildDir/$libsDirName/$jarArchiveName"))
-
-
-
-
println configurations.compile.asPath
-
-
-
-
/*从子项目拷贝War任务生成的压缩包到根项目的build/explodedDist目录*/
-
task explodedDist(type: Copy) {
-
into "$buildDir/explodedDist"
-
-
-
-
九、启动web子模块的application启动类,访问localhost:8080/hello
十、打包:
在父工程目录下输入命令 gradle build
取出 web子模块下 build -> libs -> web-1.0.jar
java -jar 执行即可访问
idea gradle+springboot 构建多项目 运行 打包
标签:snap nts 3.1 connector XML student .class ldd put
原文地址:https://www.cnblogs.com/woshuyuqiang/p/9276761.html