tips:按照以下步骤创建项目可少走弯路
本教程测试时使用IDEA 2022.2.3,使用其他版本的操作应该也类似
父项目名:parent-project
后端子模块名:server
前端子模块名:web
请根据实际需要进行调整,如使用其他的项目名或创建多个子模块
// build.gradle.kts (parent-project)
group = "com.example"
version = "0.0.1-SNAPSHOT"
// build.gradle.kts (server)
plugins {
java
id("org.springframework.boot") version "3.3.4"
id("io.spring.dependency-management") version "1.1.6"
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
configurations {
compileOnly {
extendsFrom(configurations.annotationProcessor.get())
}
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.3")
compileOnly("org.projectlombok:lombok")
developmentOnly("org.springframework.boot:spring-boot-devtools")
runtimeOnly("com.mysql:mysql-connector-j")
annotationProcessor("org.projectlombok:lombok")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.mybatis.spring.boot:mybatis-spring-boot-starter-test:3.0.3")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
tasks.withType {
useJUnitPlatform()
}
重新加载所有gradle项目并重新启动IDEA(如果代码洞察不可用)
在Spring Boot子模块(server)的代码根目录java目录下创建Spring Boot启动类com.example.server.ServerApplication
@SpringBootApplication
public class ServerApplication {
public static void main(String[] args) {
SpringApplication.run(ServerApplication.class, args);
}
}
spring:
application:
name: server
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
url: ${DB_URL}
先决条件:已安装Node.js
tips:Windows推荐使用nvm安装node,以便切换版本
参考链接:在 Windows 上安装 Node.js、nvm-windows发布页面
npm create vue@latest
创建vue3项目(web),按照提示完成项目创建。根据提示使用cd web
、npm install
完成项目初始化。import com.github.gradle.node.npm.task.NpmTask
plugins {
id("com.github.node-gradle.node") version "7.1.0"
}
node {
download.set(false)
}
tasks.register("build") {
group = "build"
args.set(listOf("run", "build"))
}
rootProject.name = "storage-service"
include("server", "web")
重新加载所有gradle项目(刷新gradle配置),完成项目创建。
检查项目是否正确创建:此时打开IDEA文件-项目结构-模块,如下图,即项目已正确创建。
参与评论
手机查看
返回顶部