Etc

maven에서 gradle로 변환...

목차

gradle설치 (for macOS)

1
brew install gradle

원래 수동으로 설치하는 방법이 있으나.. 나는 위와 같이 자동 설치를 좋아한다 ~~대부분 그렇지 않을까~~~
수동 설치는 사이트에서 참고하자 https://gradle.org/gradle-download/

pom.xml -> build.gradle로 변환

1
2
# 프로젝트 폴더 (pom.xml이 있는곳) 으로 이동 
gradle init --type pom

위와 같이 하면 project name 및 dependencies 등이 gralde용 build script로 변환이 되고 프로젝트가 gradle를 사용가능하도록 설정된다

intelliJ IDEA에서 기존 maven으로 구성된 프로젝트라면 module을 새로 import해야 한다 (그래야 툴에서 인식이 되는듯 하다)
꼭 import할때 build.gralde를 선택하자

build.gradle 수정

  1. 웹배포용이므로 apply plugin: 'war' 를 추가 한다

  2. sourceSets를 지정해 빌드 옵션에 맞추어 특정 resource를 로드 하게 설정 한다

1
2
3
4
sourceSets {
    main.java.srcDirs=['src/main/java']
    main.resources.srcDirs=['src/main/resources', 'src/main/resources-' + target]
}
  1. war파일명 지정과 webContent 패스를 지정한다
1
2
3
4
war {
    archiveName 'api.war'
    from 'webapp' // adds a file-set to the root of the archive
}

완성된 build.gradle

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
apply plugin: 'java'
apply plugin: 'war'

group = 'com.sample'
version = '1.0.0'

description = """api-server"""

sourceCompatibility = 1.7
targetCompatibility = 1.7

repositories {
    mavenCentral()
}

dependencies {
    compile(group: 'org.springframework', name: 'spring-context', version:'4.2.1.RELEASE') {
        exclude(module: 'commons-logging')
    }
    compile group: 'org.springframework', name: 'spring-webmvc', version:'4.2.1.RELEASE'
    compile group: 'org.springframework', name: 'spring-jdbc', version:'4.2.1.RELEASE'
    compile group: 'org.springframework', name: 'spring-aop', version:'4.2.1.RELEASE'
    compile group: 'org.springframework.security', name: 'spring-security-core', version:'3.2.5.RELEASE'
    compile group: 'org.springframework.data', name: 'spring-data-jpa', version:'1.9.0.RELEASE'
    compile group: 'org.springframework.amqp', name: 'spring-rabbit', version:'1.4.1.RELEASE'
    
    compile group: 'commons-fileupload', name: 'commons-fileupload', version:'1.2'
    compile group: 'commons-httpclient', name: 'commons-httpclient', version:'3.0.1'
    compile group: 'commons-dbcp', name: 'commons-dbcp', version:'1.4'
    compile group: 'commons-lang', name: 'commons-lang', version:'2.6'
    compile group: 'commons-io', name: 'commons-io', version:'2.4'
    compile group: 'commons-codec', name: 'commons-codec', version:'1.10'
    compile group: 'commons-net', name: 'commons-net', version:'3.3'
    
    compile group: 'ch.qos.logback', name: 'logback-classic', version:'1.0.13'
    compile group: 'org.slf4j', name: 'slf4j-api', version:'1.7.5'
    compile group: 'com.google.code.gson', name: 'gson', version:'2.2.2'
    compile group: 'mysql', name: 'mysql-connector-java', version:'5.1.5'
    compile group: 'org.hibernate', name: 'hibernate-entitymanager', version:'4.3.8.Final'
    compile group: 'com.sun.scn', name: 'sysnet-registration', version:'1.0.1'
    testCompile group: 'org.springframework', name: 'spring-test', version:'4.2.1.RELEASE'
    testCompile group: 'junit', name: 'junit', version:'4.11'
    providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version:'3.0.1'
}


sourceSets {
    main.java.srcDirs=['src/main/java']
    main.resources.srcDirs=['src/main/resources', 'src/main/resources-' + target]
}

war {
    archiveName 'api.war'
    from 'webapp' // adds a file-set to the root of the archive
}

빌드

빌드시에 Script Parameters를 함께 넣어야 한다 빌드옵션

빌드 결과물은 build/libs/api.war 로 확인 할 수 있다

개발시 개발서버에 바로 배포를 하기 위한 구성 추가 하기!

아래 cargo plugin을 통하여 가능하다 https://github.com/bmuschko/gradle-cargo-plugin

build.gradle에 아래 추가

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.bmuschko:gradle-cargo-plugin:2.2.3'
    }
}

apply plugin: 'com.bmuschko.cargo'
...
중략...
...

cargoRedeployRemote {
    dependsOn war
}

cargoDeployRemote {
    dependsOn war
}

cargo {
    containerId = 'tomcat7x'
    port = 8083

    deployable {
        context = 'api'
    }

    remote {
        hostname = '172.1.20.22'
        username = 'tomcat'
        password = 'password'
    }
}

터미널창에서 실행

1
gradle -Ptarget=dev cargoRedeployRemote