프로그래밍/Java

스프링 부트 + vue.js gradle build 과정에서 npm build 자동으로 수행되도록

소행성왕자 2021. 11. 23. 13:10
plugins {
    id "com.github.node-gradle.node" version "3.1.1"
}

node {
    download = true
    version = "14.6.0"
    npmVersion = "6.14.7"
    distBaseUrl = "https://nodejs.org/dist"
    npmInstallCommand = "install"
    workDir = file("${project.projectDir}/.gradle/nodejs")
    npmWorkDir = file("${project.projectDir}/.gradle/npm")
    nodeProjectDir = file('./front')
}

task setUp(type: NpmTask) {
    description = "Install Node.js Packages"
    args = ['install']
}

task buildFrontEnd(type: NpmTask, dependsOn: setUp) {
    description = "build Vue"
    args = ['run', 'build']
}

sourceSets {
    main {
        resources {
            srcDir './src/resources/static'
        }
    }
}

processResources.dependsOn 'buildFrontEnd'

build.gradle 전체

plugins {
    id 'org.springframework.boot' version '2.5.6'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
    id "com.github.node-gradle.node" version "3.1.1"
    id 'war'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

node {
    download = true
    version = "14.6.0"
    npmVersion = "6.14.7"
    distBaseUrl = "https://nodejs.org/dist"
    npmInstallCommand = "install"
    workDir = file("${project.projectDir}/.gradle/nodejs")
    npmWorkDir = file("${project.projectDir}/.gradle/npm")
    nodeProjectDir = file('./front')
}


task setUp(type: NpmTask) {
    description = "Install Node.js Packages"
    args = ['install']
}

task buildFrontEnd(type: NpmTask, dependsOn: setUp) {
    description = "build Vue"
    args = ['run', 'build']
}

sourceSets {
    main {
        resources {
            srcDir './src/resources/static'
        }
    }
}

processResources.dependsOn 'buildFrontEnd'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
    all {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-web-services'
    implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.2.0'
    implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect' /* Thymeleaf Layout */
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    runtimeOnly 'com.h2database:h2'
    runtimeOnly 'mysql:mysql-connector-java'
    annotationProcessor 'org.projectlombok:lombok'
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    implementation 'org.springframework.boot:spring-boot-starter-log4j2'
    implementation 'org.bgee.log4jdbc-log4j2:log4jdbc-log4j2-jdbc4.1:1.16'

}

test {
    useJUnitPlatform()
}