Previous-compilation-data.bin

Using Gradle 7.4.2, when I create a ZIP archive of my main Java code, the resulting archive contains a file called previous-compilation-data.bin. This appears to be an artifact of Gradle’s incremental build process, because if I disable incremental compilation, the file is no longer generated. previous-compilation-data.bin is located in the build/tmp/compileJava folder after building the project and I’m somewhat surprised this file is included in the generated ZIP archive using the following build script:

plugins {
    id 'java'
}

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

task buildZip(type: Zip) {
    from compileJava
    from processResources
    into('lib') {
        from configurations.runtimeClasspath
    }
    reproducibleFileOrder = true
    preserveFileTimestamps = false
}

If I modify my ZIP task I can exclude the file, but this doesn’t feel like a robust solution to me:

task buildZip(type: Zip) {
    from compileJava
    from processResources
    into('lib') {
        from configurations.runtimeClasspath
    }
    exclude 'previous-compilation-data.bin'
    reproducibleFileOrder = true
    preserveFileTimestamps = false
}

Is it expected behaviour that the main sourceSet includes the files in build/tmp/ and if so, is there a better way to exclude previous-compilation-data.bin from my ZIP archive?

Instead of packaging the outputs of the compileJava and processResources tasks directly, you can package the outputs of the main sourceset using from sourceSets.main.output.

Alternatively, if you don’t need the class and resource files directly in your zip, you can package the jar using from tasks.jar. If you didn’t know, there is an application plugin that builds a distribution zip with the libs, jar, and some startup scripts.

Thanks @Chris_Dore. Your suggestion worked perfectly and the previous-compilation-data.bin file is no longer included in the ZIP archive.

I was aware of the application plugin but in this particular case I’m packaging the source files for an AWS Lambda and I’ve no need for scrips to bootstrap the application.