본문 바로가기

Tools 스토리

gradle 기능설명

이글은 Gradle Plugin Cargo에 대해 이야기 해보고자 한다. Cargo는 Gradle 빌드에서 로컬 및 원격 컨테이너에 웹응용프로그램의 배포 기능을 제공해 주는 역할한다.  WAR과 EAR Artifacts 지원

1. 빌드스크립트가 외부 플러그인에 의존적일 때 buildscript를 사용
/*
   주석 내용이 어떻게 나오나 봅시다.
*/
    repositories {
        maven { url 'http://repo.springsource.org/plugins-release' }
        jcenter()
    }
    dependencies {
        classpath 'org.gradle.api.plugins:gradle-cargo-plugin:1.3'
    }
}

2. cargo는 특정 Gradle 빌드에서 로컬 및 원격 컨테이너에 웹 응용 프로그램의 배포 기능을 제공
/*
    configure(subprojects.findAll { it.name.endsWith('webapp') }) 내용은 ?
    서브 프로젝트 중 webapp로 끝나는 프로젝트에 대해 아래와 같은 설정을 하라는 의미이다.
*/
configure(subprojects.findAll { it.name.endsWith('webapp') }) {
    apply plugin: 'war'
    apply plugin: 'tomcat'
    apply plugin: 'cargo'
/*
	apply plugin: 'cargo'
	웹사이트 : https://github.com/bmuschko/gradle-cargo-plugin
*/
    dependencies {
        def cargoVersion = '1.4.5'
        cargo "org.codehaus.cargo:cargo-core-uberjar:$cargoVersion"
        cargo "org.codehaus.cargo:cargo-ant:$cargoVersion"
    }

    cargo {
        containerId = 'tomcat7x'
        port = 8080
    }

    if(project.hasProperty('target')) {
        war {
            webxml = 'webxml/web.xml'
        }
        dependencies {
            compile(group: 'net.bull.javamelody', name: 'javamelody-core', version: '1.47.0')
            compile(group: 'com.lowagie', name: 'itext', version: '2.1.7') {
                exclude(module: 'bcmail-jdk14')
                exclude(module: 'bcprov-jdk14')
                exclude(module: 'bctsp-jdk14')
            }
        }
        if(project.target.equals('development')) {
            cargo {
                deployable {
                    context = "brms"
                }
                remote {
                    hostname = '개발 호스트이름 or 아이피주소'
                    username = '매니저아이디'
                    password = '패스워드'
                }
            }
        } else if(project.target.equals('public')) {
            war {
                processResources {
                    exclude '**/images/*.*'
                }
            }

            cargo {
                deployable {
                    context = "/"
                }
                remote {
                    hostname = '운영 호스트이름 or 아이피주소'
                    username = '매니저아이디'
                    password = '패스워드'
                }
            }
        } else {
            logger.error("target is not defined : dev or pub")
        }
    } else {
        logger.error("target is not defined : dev or pub")
    }

    cargoRedeployRemote {
        dependsOn war
    }

    cargoDeployRemote {
        dependsOn war
    }

    tomcatRun {
        httpPort = 8080
        httpsPort = 8443
        URIEncoding = 'UTF-8'
    }

    dependencies {
        String tomcatVersion = '7.0.47'
        tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}"
        tomcat("org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}") {
            exclude group:'org.slf4j'
            exclude(group: 'commons-logging', module: 'commons-logging')
        }
        tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
            exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
        }
        compile("org.springframework:spring-webmvc:${rootProject.ext.springVersion}") {
            exclude(group: 'commons-logging', module: 'commons-logging')
        }
        compile 'org.springframework.security:spring-security-web:3.2.0.RELEASE'
        compile 'org.springframework.security:spring-security-config:3.2.0.RELEASE'

        providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
        providedCompile 'javax.websocket:javax.websocket-api:1.0'
        providedCompile('javax.servlet:jsp-api:2.0') {
            exclude group:"javax.servlet"
        }
        providedCompile "org.apache.tomcat:tomcat-servlet-api:${tomcatVersion}"
    }
}

2개의 Plugins 을 제공
Plugin IdentifierDepends OnTypeDescription
cargo-base-CargoBasePluginProvides Cargo custom task types, pre-configures classpath and deployables.
cargocargo-baseCargoPluginProvides a set of local and remote Cargo tasks and exposes extension for configuration.


Cargo Tasks 설정

Task NameDepends OnTypeDescription
cargoDeployRemote-CargoDeployRemoteDeploys web application to remote container.
cargoUndeployRemote-CargoUndeployRemoteUndeploys a web application from remote container.
cargoRedeployRemote-CargoRedeployRemoteRedeploys web application to remote container.
cargoRunLocal-CargoRunLocalStarts the local container, deploys web application to it and wait for the user to press CTRL + C to stop.
cargoStartLocal-CargoStartLocalStarts the local container, deploys web application to it and then do other tasks (for example, execute tests).
cargoStopLocal-CargoStopLocalStops local container.