작성
·
1.4K
1
Requirements
static/node_module로 package.json에 선언된 의존성을 다운로드 받아야한다
gradle build 시 package.json에 선언된 의존성을 확인하고 다시 다운로드 받아야 한다.
뭔가 간단하게 끝내고 싶다 !!!
Action
https://github.com/node-gradle/gradle-node-plugin/blob/master/docs/usage.md
다양한 관련 플러그인 들이 있지만, 위의 플러그인을 설치 했습니다.
2번의 요구사항은 gradle의 증분 컴파일(?)이 해주는 것 같습니다. (정확하지 않음 추측이에요)
3번은 관련 자료를 찾던 도중 processResources 를 발견했고, Copies production resources into the production resources directory. 라고 설명 되어 있습니다.(공식 홈페이지)
따라서, npm install 시 node_module 파일을 static 이하로 떨어 뜨리면 되겠구나!
그리고 processResources를 "npm install 동작을하는 " Task를 의존하게 하면 되겠구나!
-- 주석이 많아 가독성이 떨어지지만, 한번 읽어보시면 더 도움이 될거라 생각해서 위의 깃헙에 있는 주석 그대로 복사 붙여넣기 합니다. 수정한 부분은 nodeProjectDir 부분과processResources.dependsOn 부분 입니다.
추가로 package.json 도 아래분이 잘 정리 해주셔서 함께 복사 붙여넣기 합니다.(고맙습니다!!)
-인텔리제이 빌드시(gradle로 설정안했을 경우 동작안해요!)
-gradle 탭 누르셔서 npm Task 들어오는지 확인해주세요!
{
"name": "static",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@yaireo/tagify": "^3.5.1",
"bootstrap": "^4.4.1",
"cropper": "^4.1.0",
"font-awesome": "^4.7.0",
"jdenticon": "^2.2.0",
"jquery": "^3.4.1",
"jquery-cropper": "^1.0.1",
"mark.js": "^8.11.1",
"moment": "^2.24.0",
"summernote": "^0.8.16"
}
}
plugins {
id "com.github.node-gradle.node" version "3.5.0"
id 'org.springframework.boot' version '2.7.5'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
id 'java'
}
group = 'me.studyOlle'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
node {
// Whether to download and install a specific Node.js version or not
// If false, it will use the globally installed Node.js
// If true, it will download node using above parameters
// Note that npm is bundled with Node.js
download = true
// Version of node to download and install (only used if download is true)
// It will be unpacked in the workDir
version = "16.14.0"
// Version of npm to use
// If specified, installs it in the npmWorkDir
// If empty, the plugin will use the npm command bundled with Node.js
npmVersion = ""
// Version of Yarn to use
// Any Yarn task first installs Yarn in the yarnWorkDir
// It uses the specified version if defined and the latest version otherwise (by default)
yarnVersion = ""
// Base URL for fetching node distributions
// Only used if download is true
// Change it if you want to use a mirror
// Or set to null if you want to add the repository on your own.
distBaseUrl = "https://nodejs.org/dist"
// Specifies whether it is acceptable to communicate with the Node.js repository over an insecure HTTP connection.
// Only used if download is true
// Change it to true if you use a mirror that uses HTTP rather than HTTPS
// Or set to null if you want to use Gradle's default behaviour.
allowInsecureProtocol = null
// The npm command executed by the npmInstall task
// By default it is install but it can be changed to ci
npmInstallCommand = "install"
// The directory where Node.js is unpacked (when download is true)
workDir = file("${project.projectDir}/.gradle/nodejs")
// The directory where npm is installed (when a specific version is defined)
npmWorkDir = file("${project.projectDir}/.gradle/npm")
// The directory where yarn is installed (when a Yarn task is used)
yarnWorkDir = file("${project.projectDir}/.gradle/yarn")
// The Node.js project directory location
// This is where the package.json file and node_modules directory are located
// By default it is at the root of the current project
nodeProjectDir = file("${project.projectDir}/src/main/resources/static")
// Whether the plugin automatically should add the proxy configuration to npm and yarn commands
// according the proxy configuration defined for Gradle
// Disable this option if you want to configure the proxy for npm or yarn on your own
// (in the .npmrc file for instance)
nodeProxySettings = ProxySettings.SMART
}
dependencies {
// View Template Engine
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
// Security
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
//Web
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation', version: '2.7.5'
//Persistence
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'com.mysql:mysql-connector-j'
// LomBok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
// Dev
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
//Test Implementation
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
}
tasks.named('test') {
useJUnitPlatform()
}
processResources.dependsOn('npmInstall')