내용으로 건너뛰기
권남
사용자 도구
로그인
사이트 도구
검색
도구
문서 보기
이전 판
역링크
최근 바뀜
미디어 관리자
사이트맵
로그인
>
최근 바뀜
미디어 관리자
사이트맵
추적:
gradle:ant
이 문서는 읽기 전용입니다. 원본을 볼 수는 있지만 바꿀 수는 없습니다. 문제가 있다고 생각하면 관리자에게 문의하세요.
====== Gradle Ant 호출 ====== * [[http://www.gradle.org/docs/current/userguide/ant.html|Using Ant from Gradle]] * build.xml을 읽어서 태스크 생성, AntBuilder 이용, "ant clean compile".execute() 형태의 호출 등이 가능하다. * [[http://www.gradle.org/docs/current/javadoc/org/gradle/api/AntBuilder.html|AntBuilder]]의 인스턴스 ''ant''를 사용하는 것이 보통이다. * [[http://groovy.codehaus.org/Using+Ant+from+Groovy|Using Ant from Groovy]] 참조 * [[http://groovy.codehaus.org/api/groovy/util/AntBuilder.html|AntBuilder]] 참조 * [[http://ant.apache.org/manual/anttaskslist.html|Ant Tasks List]] * AntBuilder의 자세한 사항은 [[:gant|Gant]]의 각 항목들을 살펴보는 것이 좋다. 특히 [[gant:tasks|Gant Tasks]]와 [[gant:antlib|Gant Ant Libraries]] 참조. ===== Ant 태스크와 타입 ===== * 항상 ''ant''라는 AntBuilder 인스턴스를 사용해 앤트 태스크를 호출할 수 있다. * ''ant.태스크이름''으로 호출한다. * 앤트 태스크 속성은 Map 형태의 파라미터로 전달한다. * 각종 Ant 태스크를 AntBuilder 형태로 변환한 것은 [[gant:tasks|Gant Tasks]] 를 참조한다. * 메시지 출력<code groovy> task hello << { String greeting = 'hello from Ant' ant.echo(message: greeting) ant.echo('hello from Ant') // 이것도 가능. } </code> * Ant 태스크의 중첩 요소들을 클로저로 표현한다.<code groovy> task zip << { ant.zip(destfile: 'archive.zip') { fileset(dir: 'src') { include(name: '**/*.xml') exclude(name: '**/*.java') } } } </code> * Ant의 타입도 태스크 처럼 메소드 이름으로 접근한다. 메소드를 호출하면 Ant의 데이터 타입을 리턴한다. * Ant path 객체를 생성하고 보여주기<code groovy> task list << { def path = ant.path { fileset(dir: 'src', includes: '**/*.xml') } path.list().each { println it } } </code> ==== 커스텀 Ant 태스크 ==== * ''ant.taskdef''<code groovy> task check << { ant.taskdef(resource: 'checkstyletask.properties') { classpath { fileset(dir: 'libs', includes: '*.jar') } } ant.checkstyle(config: 'checkstyle.xml') { fileset(dir: 'src') } } </code> * 커스텀 Ant 태스크에 의존성 지정하기 * 먼저 의존성 태스크 이름으로 의존성을 지정한다.<code groovy> configurations { pmd // pmd 라는 설정이 생기고 } dependencies { pmd group: 'pmd', name: 'pmd', version: '4.2.5' // pmd 설정에 의존성을 지정한다. } </code> * ''configurations.이름.**asPath**''로 의존성 사용<code groovy> task check << { ant.taskdef(name: 'pmd', classname: 'net.sourceforge.pmd.ant.PMDTask', classpath: configurations.pmd.asPath) ant.pmd(shortFilenames: 'true', failonruleviolation: 'true', rulesetfiles: file('pmd-rules.xml').toURI().toString()) { formatter(type: 'text', toConsole: 'true') fileset(dir: 'src') } } </code> ===== Ant 빌드 가져오기 ===== * ''ant.importBuild()''로 build.xml을 직접 읽어올 수 있다. * **각 Ant 태스크는 Gradle 태스크로 변환된다.** * 간단한 build.xml 로딩 * ''build.gradle''<code groovy> ant.importBuild 'build.xml' </code> * ''build.xml''<code xml> <project> <target name="hello"> <echo>Hello, from Ant</echo> </target> </project> </code> * 이제 ''gradle hello''로 Ant 타겟을 Gradle 태스크인 것 처럼 실행할 수 있다. * Ant 타겟에 다른 액션 추가, 의존하기 등도 가능하면 Ant 태스크가 Gradle 태스크에 의존하는 것도 가능하다.<code xml> <project> <target name="hello" depends="intro"> <!-- intro는 Gradle 태스크 --> <echo>Hello, from Ant</echo> </target> </project> </code> ===== Ant Properties ===== * 다음과 같이 Ant 프라퍼티를 설정할 수 있다.<code groovy> ant.buildDir = buildDir ant.properties.buildDir = buildDir ant.properties['buildDir'] = buildDir ant.property(name: 'buildDir', location: buildDir) </code> * Ant 프라퍼티 읽기<code> // build.xml에서 프라퍼티를 설정했을 때 <property name="antProp" value="a property defined in an Ant build"/> // 다음처럼 읽는다. println ant.antProp println ant.properties.antProp println ant.properties['antProp'] </code> * Ant 레퍼런스 설정과 읽기 * 설정<code> // 레퍼런스 설정 ant.path(id: 'classpath', location: 'libs') // id 지정 방식 ant.references.classpath = ant.path(location: 'libs') // 명시적으로 references에 넣기 ant.references['classpath'] = ant.path(location: 'libs') // [] 연산자 이용 // build.xml에서 참조 가능 <path refid="classpath"/> </code> * 읽어오기<code> // build.xml에 설정된 값을 <path id="antPath" location="libs"/> // 다음처럼 읽는다. println ant.references.antPath println ant.references['antPath'] </code> ===== java task ===== [[https://ant.apache.org/manual/Tasks/java.html|Ant Java 태스크]]는 Java 클래스를 실행한다. [[gradle:java|Gradle Java Plugin]]에서 ''JavaExec''를 사용하는 방법도 있다. <code groovy> ant.java(classname: '실행할JavaClass', fork: true, classpath: configurations.임의의Config.asPath) { arg(value: '파라미터1') arg(value: '파라미터2') ... } </code> ===== zip task ===== * 일반적인 zip 압축<code groovy> task zip << { ant.zip(destfile: 'archive.zip') { fileset(dir: 'src') { include(name: '**/*.xml') exclude(name: '**/*.java') } } } </code> * 파일들을 압축파일의 특정 디렉토리에 넣기 [[https://ant.apache.org/manual/Types/zipfileset.html|ZipFileSet]]<code groovy> // resources.zip 파일의 resources/ 디렉토리로 압축 ant.zip(destfile: "${buildDir}/resources.zip") { zipfileset(dir: "${webAppDirName}/WEB-INF/resources", prefix: "resources") } </code>
gradle/ant.txt
· 마지막으로 수정됨: 2014/06/27 15:05 저자
kwon37xi
문서 도구
문서 보기
이전 판
역링크
맨 위로