在Github中找到一个合适的项目spring-boot-vuejs,下载准备构建。但是原项目只有maven配置,而我想用gradle构建。上网查到gradle自带转换POM的功能,虽然这还是个孵化中的特性:
gradle init --type pom
直接在项目根目录执行上面的命令,会自动生成gradle的相关文件。
之后,我直接使用系统命令构建,不是使用生成的gradlew,然后运行生成的jar包:
gradle build
java -jar ./backend/build/libs/backend-0.0.1-SNAPSHOT.jar
未能成功运行项目:
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=gasp
build/libs/backend-0.0.1-SNAPSHOT.jar中没有主清单属性
手动修改backend项目的build.gradle:
plugins {
id 'org.springframework.boot' version '2.1.6.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
repositories {
mavenCentral()
}
jar {
baseName = 'spring-boot-vuejs'
version = '0.1.0'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-devtools'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'com.h2database:h2:1.4.199'
compile 'org.apache.tomcat:tomcat-jdbc:9.0.21'
compile 'org.postgresql:postgresql:42.2.5'
compile 'org.springframework.boot:spring-boot-starter-security'
testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompile 'io.rest-assured:rest-assured:4.0.0'
testCompile 'org.springframework.security:spring-security-test'
}
再次构建还是失败:
ydx@ydx-PC:$ gradle build
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=gasp> Task :backend:compileTestJava FAILED
/home/ydx/Documents/Project/spring_boot/spring-boot-vuejs-master/backend/src/test/java/de/jonashackt/springbootvuejs/controller/BackendControllerTest.java:59: 错误: 无法访问TypeRef
.body().as(Long.class);
^
找不到io.restassured.common.mapper.TypeRef的类文件
1 个错误FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':backend:compileTestJava'.
> Compilation failed; see the compiler error output for details.
先不管后端,捣鼓一下前端项目。因为不会用gradle调用npm命令,所以直接执行:
npm install
结果node-sass没有安装成功-_-||
只好手动安装:
cnpm install --save-dev node-sass
成功后执行:
npm run serve
O(∩_∩)O哈哈哈~,成功启动。
当然,只是前端启动了,后端还是全身不遂%>_<%