Etc

Converting from maven to gradle...

Contents

Install gradle (for macOS)

1
brew install gradle

There’s a manual install method.. but I prefer automatic installs like the above ~~doesn’t everyone~~~
For manual install see the site https://gradle.org/gradle-download/

Convert pom.xml -> build.gradle

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

Doing the above converts project name, dependencies, etc. into a gradle build script and sets up the project to use gradle

If it’s an existing maven project in intelliJ IDEA, you need to import the module again (seems that’s how the tool recognizes it)
Make sure to select build.gralde when you import

Edit build.gradle

  1. It’s for web deployment, so add apply plugin: 'war'

  2. Set sourceSets so specific resources are loaded depending on the build option

1
2
3
4
sourceSets {
    main.java.srcDirs=['src/main/java']
    main.resources.srcDirs=['src/main/resources', 'src/main/resources-' + target]
}
  1. Set the war file name and the webContent path
1
2
3
4
war {
    archiveName 'api.war'
    from 'webapp' // adds a file-set to the root of the archive
}

Finished 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
}

Build

You need to pass Script Parameters when building build options

The build output can be found at build/libs/api.war

Add a setup to deploy straight to the dev server during development!

Possible with the cargo plugin below https://github.com/bmuschko/gradle-cargo-plugin

Add the following to 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'
    }
}

Run in the terminal

1
gradle -Ptarget=dev cargoRedeployRemote