[해커톤] BE,FE build

Kyeong Ju·2022년 8월 17일
0

프로젝트 - bliond

목록 보기
4/8

build

1. build.gradle 파일 수정

// build.gradle
def frontendDir = "$projectDir/src/main/frontend"

sourceSets {
	main {
		resources { srcDirs = ["$projectDir/src/main/resources"]
		}
	}
}

processResources { dependsOn "copyReactBuildFiles" }

task installReact(type: Exec) {
	workingDir "$frontendDir"
	inputs.dir "$frontendDir"
	group = BasePlugin.BUILD_GROUP
	if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
		commandLine "npm.cmd", "audit", "fix"
		commandLine 'npm.cmd', 'install' }
	else {
		commandLine "npm", "audit", "fix" commandLine 'npm', 'install'
	}
}

task buildReact(type: Exec) {
	dependsOn "installReact"
	workingDir "$frontendDir"
	inputs.dir "$frontendDir"
	group = BasePlugin.BUILD_GROUP
	if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
		commandLine "npm.cmd", "run-script", "build"
	} else {
		commandLine "npm", "run-script", "build"
	}
}

task copyReactBuildFiles(type: Copy) {
	dependsOn "buildReact"
	from "$frontendDir/build"
	into "$projectDir/src/main/resources/static"
}

2. ./gradlew build

home directory에서 ./gradlew build 를 실행한다.
아래와 같이 BUILD SUCCESSFUL이 나오면 성공한 것이다.

빌드된 jar 파일은 build/libs 에서 확인가능하다.

3. 결과

1번과 2번을 실행하고 나면 npm start를 통해 따로 프론트엔드를 실행시키지 않고, 빌드하여 실행하면 프론트엔드 코드와 백엔드 코드가 동시에 실행된다.


결과 : 하지만 백엔드 파일과 프론트엔드 파일을 따로 관리하기로 결정하였다. 따라서 빌드를 할 필요는 없지만 첫 시도에 의미를 두기로 하였다.

profile
백엔드 취준생

0개의 댓글