Archive Extract

A Gradle plugin that extracts and renames files from dependency archives (JARs, ZIPs) into your project.

Usage

build.gradle
plugins {
    id 'java'
    id 'no.conta.archive-extract' version '1.0.7'
}
The plugin will automatically:
  • Create an extractArchives lifecycle task that runs all configured extractions

  • Wire extraction tasks to run before processResources when the Java plugin is applied

Configuration

Configure sources using the archiveExtract container. Each source specifies an archive to extract from, which files to include, and how to handle them.

build.gradle
archiveExtract {
    mySchema {
        from 'com.example:schema-archive:1.0.0'
        into 'src/main/resources'
        include '**/*.xsd'

        files {
            rename 'com/example/schemas/main.xsd', 'schema.xsd'
            keep 'com/example/schemas/types.xsd'
            skip 'com/example/schemas/deprecated.xsd'
        }
    }
}

Source properties

from

The archive source. Either a dependency notation string (e.g. 'group:artifact:version') or a File reference.

into

The output directory for extracted files. Defaults to src/main/resources.

include

Glob pattern to filter which files in the archive are considered. Can be called multiple times. If no includes are specified, all files are included.

File mappings

Every file matched by include must be accounted for in the files block. The task will fail if any matched file is not mapped.

rename

Extract the file and rename it. Takes the full archive path and the target filename.

keep

Extract the file using its original filename (without directory path).

skip

Ignore the file (do not extract it).

Tasks

extractArchives

Lifecycle task that depends on all per-source extraction tasks.

extractNameArchive

Per-source task that extracts files from the named source. For example, a source named mySchema creates a task extractMySchemaArchive.

Examples

Dependency notation

archiveExtract {
    openapi {
        from 'com.example:api-spec:2.1.0'
        include '**/*.yaml'

        files {
            rename 'specs/openapi.yaml', 'api.yaml'
        }
    }
}

File-based source

archiveExtract {
    local {
        from file('libs/schemas.zip')
        into 'src/main/resources/schemas'
        include '**/*.json'

        files {
            keep 'schemas/v1/config.json'
            skip 'schemas/v1/legacy.json'
        }
    }
}

Multiple sources

archiveExtract {
    schemas {
        from 'com.example:schema-archive:1.0.0'
        include '**/*.xsd'

        files {
            rename 'com/example/main.xsd', 'schema.xsd'
        }
    }

    templates {
        from 'com.example:template-archive:1.0.0'
        into 'src/main/resources/templates'
        include '**/*.ftl'

        files {
            keep 'templates/email.ftl'
            keep 'templates/invoice.ftl'
            skip 'templates/test.ftl'
        }
    }
}