Skip to content

Latest commit

 

History

History
86 lines (59 loc) · 3.52 KB

README.md

File metadata and controls

86 lines (59 loc) · 3.52 KB

Tested on Java LTS versions from 8 to 21.

Tested on Gradle versions from 6.0 to 8.11-rc-3.

name.remal.merge-resources plugin

configuration cache: supported from v2

This plugin configures all AbstractCopyTask tasks to merge files with the same RelativePath.

The main use cases are:

  • building fat JARs
  • generating some files via annotation processors and configuring the same files manually

Configuration

mergeResources {
  metaInfServices {
    enabled = false // To disable merging `META-INF/services/*`
  }
  packageInfo {
    enabled = false // To disable merging `META-INF/services/*`
  }
  metaInfServices {
    enabled = false // To disable merging `**/package-info.class`
  }
  moduleInfo {
    enabled = false // To disable merging `**/module-info.class`
  }
  springFactories {
    enabled = false // To disable merging `META-INF/spring.factories`
  }
  springImports {
    enabled = false // To disable merging `META-INF/spring/*.imports`
  }

  // To merge all `*.jar` files with the same relative path:
  addResourceMerger('**/*.jar') { RelativePath relativePath, Collection<File> files ->
    return new ByteArrayInputStream(new byte[0]) // `InputStream` should be returned `addResourceMerger`
  }

  // To merge all `*.text` files with the same relative path:
  addTextResourceMerger('**/*.jar', 'US-ASCII') { RelativePath relativePath, Collection<File> files ->
    return '' // `String` should be returned for `addTextResourceMerger`
  }
  addTextResourceMerger('**/*.jar' /* UTF-8 is default charset */) { RelativePath relativePath, Collection<File> files ->
    return '' // `String` should be returned for `addTextResourceMerger`
  }
}

Built-in mergers

META-INF/services/*

Excluding:

  • META-INF/services/org.codehaus.groovy.runtime.ExtensionModule

These files are used for Java's java.util.ServiceLoader.

When these files are merged, all comments and duplications are removed.

**/package-info.class

The file with the most number of package annotations is taken.

For the other files, there is a check that validates that their package annotations present in the result file.

**/module-info.class

Different sections of module-info are merged.

It's required that all merged files have the same module name.

META-INF/spring.factories

See org.springframework.core.io.support.SpringFactoriesLoader.

META-INF/spring/*.imports

See META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports files.

See org.springframework.boot.context.annotation.ImportCandidates.