2

I have project A with SubProjects

A/B A/C

(B and C subprojects). B and C are compiled into A into one Jar file. Using the below code.

gradle.taskGraph.whenReady {
    jar {
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }

    manifest {
        attributes("Main-Class": "brut.apktool.Main")
    }
    }
}

That works fine, but I have a prebuilt JAR in /a/b/src/main/resources/prebuilt.jar. This jar just encapsulates some random files I need during the program. There isn't any java or anything. I grab them from inputStream, but after building with Gradle it converts binary newline data and then messes up the archive.

I tried copying the jar using a CopyTask post built, but I never could get a Task to run prior to the gradle.TaskGraph.whenReady.

Back in Maven. I would just disable filtering for that file, but cannot find the same expression in Gradle.

EDIT: This is what I do currently, and it filters my changes into the properties files, but doesn't do my newline filtering.

processResources {
    ext.fullrev = ''
    ant.loadfile(srcFile: "../../.git/refs/heads/master", property: ext.fullrev)
        filter(FixCrLfFilter)
    filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [version: apktoolversion, gitrev: ant.properties[ext.fullrev].substring(0,10)])
}
Connor Tumbleson
  • 3,270
  • 2
  • 25
  • 37

1 Answers1

1

Well solved it. For future googlers.

processResources {
    from('src/main/resources/properties') {
        include '**/*.properties'
        into 'properties'
        ext.fullrev = ''
        ant.loadfile(srcFile: "../../.git/refs/heads/master", property: ext.fullrev)
        filter(ReplaceTokens, tokens: [version: apktoolversion, gitrev: ant.properties[ext.fullrev].substring(0,10)])
    }
    from('src/main/resources/') {
        include '**/*.jar'
    }

    includeEmptyDirs = false
}

Pretty simple to explain. If the file falls into my *.properties include, then its filtered etc.

If it falls into *.jar, its just copied onward without filtering. Prevents graddle/plugin from filtering binary newlines in JAR files.

JesusFreke
  • 19,784
  • 5
  • 65
  • 68
Connor Tumbleson
  • 3,270
  • 2
  • 25
  • 37