2015-01-06 3 views
0

다른 입력 파일의 특정 세트를 취하는 사용자 정의 Gradle 작업을 작성하려고합니다. 다른 디렉토리, 출력 파일에있을 수 있으며 입력이있는 javaexec를 호출합니다.Gradle CustomTask 종속성에 대한 InputFiles 고려하지

현재 @OutputFile이 존재하지만 입력 파일 목록을 고려하지 않고 출력 파일보다 최신 파일 인 경우 @TaskAction을 건너 뛸 곳이 있습니다.

class JavaCPPTask extends DefaultTask { 
    def className = [] 
    String outputDir = "" 
    String localClasspath = "bin/classes" 
    String runIfExists = "" 
    String javacpp = "libs/javacpp.jar" 
    String outputName = "" 

    //@InputDirectory 
    //File inputFile = new File("bin/classes/com/package/ve") 

    @InputFiles 
    List<File> getInputFiles() { 
     ArrayList<File> inputFiles = new ArrayList<File>() 
     for (int i = 0; i < className.size(); i++) { 
     def inputFileStr = localClasspath + '/' + className.get(i).replace('.','/') + '.class' 
     println("InputFileStr: " + inputFileStr) 
     File inputFile = new File(inputFileStr) 
     println("Input file exists? " + inputFile.exists()) 
     inputFiles.add(inputFile) 
     } 
     return inputFiles 
    } 


    @OutputFile 
    File getTargetFile() { 
     if (outputName.length() == 0) { 
      def nameWithPackage = className.get(0) 
      def name = nameWithPackage.substring(nameWithPackage.lastIndexOf(".")+1) 
      outputName = 'jni' + name; 
     } 

     File outputFile = new File(outputDir + outputName + '.cpp'); 
     println("Output Name is: " + outputFile) 
     println("Output file exists? " + outputFile.exists()) 
     return outputFile 
    } 

    JavaCPPTask() { 
    } 

    @TaskAction 
    def javacpp() { 

     def haveFile = new File(runIfExists) 
     if (runIfExists.length() > 0 && ! haveFile.exists()) { 
     println("Skipping class " + className + " makefile does not exist: " + runIfExists); 
     } 
     else { 
     def useOutputName = [] 
     if (outputName.length() > 0) { 
      useOutputName = [ '-o', outputName ] 
     } 
     def optionArray = [ '-nocompile', '-classpath', localClasspath, '-d', outputDir ] 
     def allOptions = [javacpp] + useOutputName + optionArray + className.findAll() 

     project.javaexec { main="-jar"; args allOptions } 

     } 
    } 
} 

def codecOpus = ['com.package.ve.CodecOpus'] 

task javaCPP_CodecOpus(type:JavaCPPTask) { 
    className = codecOpus 
    outputDir = 'jni/VECodecOpus/' 
    runIfExists = outputDir + 'Android.mk' 
} 

그리고 나 도움이되지 않을 수도 있습니다 출력 : 여기에

는 관련 빌드 파일의 부분입니다. 출력 파일은 이전 실행에 의해 이미 생성되었지만 대상이 다시 실행될 것으로 예상되므로 .class 파일이 업데이트되었습니다.

> c:\java\gradle-2.2.1\bin\gradle -b build 

JavaCPP.gradle javaCPP_CodecOpus 
Incremental java compilation is an incubating feature. 
InputFileStr: bin/classes/com/package/ve/CodecOpus.class 
Input file exists? true 
:javaCPP_CodecOpus 
InputFileStr: bin/classes/com/package/ve/CodecOpus.class 
Input file exists? true 
Output Name is: jni\VECodecOpus\jniCodecOpus.cpp 
Output file exists? true 
Output Name is: jni\VECodecOpus\jniCodecOpus.cpp 
Output file exists? true 
Output Name is: jni\VECodecOpus\jniCodecOpus.cpp 
Output file exists? true 
Output Name is: jni\VECodecOpus\jniCodecOpus.cpp 
Output file exists? true 
InputFileStr: bin/classes/com/package/ve/CodecOpus.class 
Input file exists? true 
:javaCPP_CodecOpus UP-TO-DATE 

BUILD SUCCESSFUL 

내가 뭘 잘못하고 있니?

답변

0

Gradle 소스를 통해 디버깅 한 후에 스크립트가 작동합니다. 새 .class 파일을 만든 .java 파일을 업데이트하고 다시 컴파일해야했지만 Gradle은 클래스 파일의 내용이 변경되지 않았다는 것을 알기에 충분히 똑똑했습니다. .java 파일에서 소스를 변경하고 다시 컴파일하면 Gradle은 소스를 변경된 것으로 올바르게 식별하고 대상을 다시 빌드합니다.

내가 Make를 너무 오랫동안 사용 해왔다.

이 토끼 구멍을 시작하기 전에 내가 깨끗한 빌드를 실행해야하기 때문에 스크립트에 여전히 문제가 있지만 날짜가 지난 입력 파일이 아닙니다.

관련 문제