Search in sources :

Example 1 with DependencyFilter

use of com.github.jengelman.gradle.plugins.shadow.internal.DependencyFilter in project checkstyle-addons by checkstyle-addons.

the class FatJarConfigAction method configureTaskFor.

@Override
protected void configureTaskFor(@Nonnull ShadowJar pFatJarTask, @Nullable DependencyConfig pDepConfig) {
    Objects.requireNonNull(pDepConfig, "required dependency config not present");
    pFatJarTask.setGroup(TaskCreator.ARTIFACTS_GROUP_NAME);
    pFatJarTask.getArchiveClassifier().set("all");
    // set appendix for archive name
    final String appendix = pDepConfig.getName();
    if (!pDepConfig.isDefaultConfig()) {
        pFatJarTask.getArchiveAppendix().set(appendix);
    }
    // dependency on the corresponding (thin) Jar task
    final Jar thinJarTask = buildUtil.getTask(TaskNames.jar, Jar.class, pDepConfig);
    pFatJarTask.dependsOn(thinJarTask);
    pFatJarTask.setDescription("Create a combined JAR of project and runtime dependencies of '" + SourceSet.MAIN_SOURCE_SET_NAME + "' for dependency configuration '" + pDepConfig.getName() + "'");
    buildUtil.inheritManifest(pFatJarTask, pDepConfig);
    pFatJarTask.from(thinJarTask.getArchiveFile());
    Configuration cfg = new ClasspathBuilder(project).buildMainRuntimeConfiguration(pDepConfig);
    pFatJarTask.setConfigurations(Collections.singletonList(cfg));
    pFatJarTask.exclude("META-INF/INDEX.LIST", "META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA", "META-INF/maven/**/*", "pom.xml");
    final Set<String> deps = getNonCheckstyleDeps(cfg);
    if (deps.size() > 0) {
        // append all licenses found in dependent Jars into one
        pFatJarTask.append("META-INF/LICENSE");
        pFatJarTask.dependencies((final DependencyFilter pDependencyFilter) -> {
            for (String dep : deps) {
                pDependencyFilter.include(pDependencyFilter.dependency(dep));
            }
        });
    }
}
Also used : Configuration(org.gradle.api.artifacts.Configuration) ClasspathBuilder(com.thomasjensen.checkstyle.addons.build.ClasspathBuilder) ShadowJar(com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) Jar(org.gradle.api.tasks.bundling.Jar) DependencyFilter(com.github.jengelman.gradle.plugins.shadow.internal.DependencyFilter)

Aggregations

DependencyFilter (com.github.jengelman.gradle.plugins.shadow.internal.DependencyFilter)1 ShadowJar (com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar)1 ClasspathBuilder (com.thomasjensen.checkstyle.addons.build.ClasspathBuilder)1 Configuration (org.gradle.api.artifacts.Configuration)1 Jar (org.gradle.api.tasks.bundling.Jar)1