Search in sources :

Example 1 with JarConfigAction

use of com.thomasjensen.checkstyle.addons.build.tasks.JarConfigAction in project checkstyle-addons by checkstyle-addons.

the class TaskCreator method setupArtifactTasks.

public void setupArtifactTasks(@Nonnull final DependencyConfigs pDepConfigs) {
    final TaskContainer tasks = project.getTasks();
    for (final DependencyConfig depConfig : pDepConfigs.getAll().values()) {
        final String pubSuffix = depConfig.getName();
        // 'generatePomProperties' task
        final String pomPropsTaskName = TaskNames.generatePomProperties.getName(depConfig);
        final TaskProvider<GeneratePomPropsTask> pomPropsTaskTaskProvider = tasks.register(pomPropsTaskName, GeneratePomPropsTask.class);
        pomPropsTaskTaskProvider.configure(pomPropsTask -> {
            pomPropsTask.getAppendix().set(depConfig.isDefaultConfig() ? null : pubSuffix);
            pomPropsTask.updateDescription();
        });
        // 'jar' task
        final String jarTaskName = TaskNames.jar.getName(depConfig);
        final TaskProvider<Jar> jarTaskProvider = tasks.register(jarTaskName, Jar.class);
        jarTaskProvider.configure(new JarConfigAction(depConfig));
        // 'fatjar' task
        final String fatjarTaskName = TaskNames.fatJar.getName(depConfig);
        final TaskProvider<ShadowJar> shadowJarTaskProvider = tasks.register(fatjarTaskName, ShadowJar.class);
        shadowJarTaskProvider.configure(new FatJarConfigAction(depConfig));
        // 'jarSources' task
        final String jarSourcesTaskName = TaskNames.jarSources.getName(depConfig);
        final TaskProvider<Jar> jarSourcesTaskProvider = tasks.register(jarSourcesTaskName, Jar.class);
        jarSourcesTaskProvider.configure(new JarSourcesConfigAction(depConfig));
        // 'jarJavadoc' task
        final String jarJavadocTaskName = TaskNames.jarJavadoc.getName(depConfig);
        final TaskProvider<Jar> jarJavadocTaskProvider = tasks.register(jarJavadocTaskName, Jar.class);
        jarJavadocTaskProvider.configure(new JarJavadocConfigAction(depConfig));
        // 'jarEclipse' task
        final String eclipseTaskName = TaskNames.jarEclipse.getName(depConfig);
        final TaskProvider<Jar> jarEclipseTaskProvider = tasks.register(eclipseTaskName, Jar.class);
        jarEclipseTaskProvider.configure(new JarEclipseConfigAction(depConfig));
        // 'jarSonarqube' task (with 'jarSonarqubeRelocate' task)
        TaskProvider<ShadowJar> jarSqTaskProvider = null;
        if (depConfig.isSonarQubeSupported()) {
            final String sqTaskName = TaskNames.jarSonarqube.getName(depConfig);
            final String relocateTaskName = TaskNames.jarSonarqubeRelocate.getName(depConfig);
            final TaskProvider<ConfigureShadowRelocation> relocationTaskProvider = tasks.register(relocateTaskName, ConfigureShadowRelocation.class);
            relocationTaskProvider.configure(relocTask -> {
                relocTask.setTarget((ShadowJar) tasks.getByName(sqTaskName));
                relocTask.setPrefix("com.thomasjensen.checkstyle.addons.shadow");
            });
            jarSqTaskProvider = tasks.register(sqTaskName, ShadowJar.class);
            jarSqTaskProvider.configure(new JarSonarqubeConfigAction(depConfig));
            jarSqTaskProvider.configure(t -> t.dependsOn(relocationTaskProvider));
        }
        final TaskProvider<ShadowJar> jarSqTaskProviderFinal = jarSqTaskProvider;
        // 'assemble' task for the dependency configuration
        TaskProvider<Task> assembleTaskProvider = null;
        if (depConfig.isDefaultConfig()) {
            assembleTaskProvider = tasks.named(BasePlugin.ASSEMBLE_TASK_NAME);
        } else {
            assembleTaskProvider = tasks.register(TaskNames.assemble.getName(depConfig));
            assembleTaskProvider.configure(assembleTask -> assembleTask.setDescription("Assembles the artifacts belonging to dependency configuration '" + depConfig.getName() + "'"));
            final TaskProvider<Task> assembleTaskProviderFinal = assembleTaskProvider;
            final TaskProvider<Task> buildTaskProvider = tasks.named(JavaBasePlugin.BUILD_TASK_NAME);
            buildTaskProvider.configure(buildTask -> buildTask.dependsOn(assembleTaskProviderFinal));
        }
        assembleTaskProvider.configure(assembleTask -> {
            assembleTask.setGroup(ARTIFACTS_GROUP_NAME);
            assembleTask.dependsOn(jarTaskProvider);
            assembleTask.dependsOn(shadowJarTaskProvider);
            assembleTask.dependsOn(jarSourcesTaskProvider);
            assembleTask.dependsOn(jarJavadocTaskProvider);
            assembleTask.dependsOn(jarEclipseTaskProvider);
            if (jarSqTaskProviderFinal != null) {
                assembleTask.dependsOn(jarSqTaskProviderFinal);
            }
        });
    }
    // disable standard 'jar' task
    tasks.named(JavaPlugin.JAR_TASK_NAME).configure(t -> t.setEnabled(false));
}
Also used : ConfigureShadowRelocation(com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation) GeneratePomPropsTask(com.thomasjensen.checkstyle.addons.build.tasks.GeneratePomPropsTask) Task(org.gradle.api.Task) JarEclipseConfigAction(com.thomasjensen.checkstyle.addons.build.tasks.JarEclipseConfigAction) ShadowJar(com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) JarSonarqubeConfigAction(com.thomasjensen.checkstyle.addons.build.tasks.JarSonarqubeConfigAction) FatJarConfigAction(com.thomasjensen.checkstyle.addons.build.tasks.FatJarConfigAction) JarConfigAction(com.thomasjensen.checkstyle.addons.build.tasks.JarConfigAction) JarJavadocConfigAction(com.thomasjensen.checkstyle.addons.build.tasks.JarJavadocConfigAction) FatJarConfigAction(com.thomasjensen.checkstyle.addons.build.tasks.FatJarConfigAction) JarSourcesConfigAction(com.thomasjensen.checkstyle.addons.build.tasks.JarSourcesConfigAction) TaskContainer(org.gradle.api.tasks.TaskContainer) ShadowJar(com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) Jar(org.gradle.api.tasks.bundling.Jar) GeneratePomPropsTask(com.thomasjensen.checkstyle.addons.build.tasks.GeneratePomPropsTask)

Aggregations

ConfigureShadowRelocation (com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation)1 ShadowJar (com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar)1 FatJarConfigAction (com.thomasjensen.checkstyle.addons.build.tasks.FatJarConfigAction)1 GeneratePomPropsTask (com.thomasjensen.checkstyle.addons.build.tasks.GeneratePomPropsTask)1 JarConfigAction (com.thomasjensen.checkstyle.addons.build.tasks.JarConfigAction)1 JarEclipseConfigAction (com.thomasjensen.checkstyle.addons.build.tasks.JarEclipseConfigAction)1 JarJavadocConfigAction (com.thomasjensen.checkstyle.addons.build.tasks.JarJavadocConfigAction)1 JarSonarqubeConfigAction (com.thomasjensen.checkstyle.addons.build.tasks.JarSonarqubeConfigAction)1 JarSourcesConfigAction (com.thomasjensen.checkstyle.addons.build.tasks.JarSourcesConfigAction)1 Task (org.gradle.api.Task)1 TaskContainer (org.gradle.api.tasks.TaskContainer)1 Jar (org.gradle.api.tasks.bundling.Jar)1