use of com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar in project micronaut-gradle-plugin by micronaut-projects.
the class AotShadowSupport method registerShadowJar.
static void registerShadowJar(Project project, ArchiveOperations archiveOperations, TaskContainer tasks, TaskProvider<Jar> optimizedJar) {
project.afterEvaluate(unused -> {
JavaApplication javaApplication = project.getExtensions().findByType(JavaApplication.class);
TaskProvider<ShadowJar> shadowProvider = tasks.register(optimizedJar.getName() + "All", ShadowJar.class, shadow -> {
shadow.setGroup(SHADOW_GROUP);
shadow.setDescription("Creates a fat jar including the Micronaut AOT optimizations");
shadow.getArchiveClassifier().convention("all-optimized");
Jar mainJar = tasks.named("jar", Jar.class).get();
shadow.getManifest().inheritFrom(mainJar.getManifest());
if (javaApplication != null) {
// This is the reason why we use an afterEvalute:
// The shadow plugin apparently does something with attributes,
// breaking support for providers
shadow.getManifest().getAttributes().put("Main-Class", javaApplication.getMainClass().get());
}
shadow.from(optimizedJar.map(jar -> archiveOperations.zipTree(jar.getArchiveFile().get())));
shadow.getConfigurations().add(project.getConfigurations().findByName("runtimeClasspath"));
shadow.getExcludes().addAll(tasks.named(ShadowJavaPlugin.SHADOW_JAR_TASK_NAME, ShadowJar.class).get().getExcludes());
});
tasks.named("assemble").configure(assemble -> assemble.dependsOn(shadowProvider));
});
}
use of com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar 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));
}
use of com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar in project OpenSearch by opensearch-project.
the class OpenSearchJavaPlugin method configureJars.
/**
* Adds additional manifest info to jars
*/
static void configureJars(Project project) {
project.getTasks().withType(Jar.class).configureEach(jarTask -> {
// we put all our distributable files under distributions
jarTask.getDestinationDirectory().set(new File(project.getBuildDir(), "distributions"));
// fixup the jar manifest
// Explicitly using an Action interface as java lambdas
// are not supported by Gradle up-to-date checks
jarTask.doFirst(new Action<Task>() {
@Override
public void execute(Task task) {
// this doFirst is added before the info plugin, therefore it will run
// after the doFirst added by the info plugin, and we can override attributes
jarTask.getManifest().attributes(new HashMap<String, Object>() {
{
put("Build-Date", BuildParams.getBuildDate());
put("Build-Java-Version", BuildParams.getGradleJavaVersion());
}
});
}
});
});
project.getPluginManager().withPlugin("com.github.johnrengelman.shadow", p -> {
project.getTasks().withType(ShadowJar.class).configureEach(shadowJar -> {
/*
* Replace the default "-all" classifier with null
* which will leave the classifier off of the file name.
*/
shadowJar.getArchiveClassifier().set((String) null);
/*
* Not all cases need service files merged but it is
* better to be safe
*/
shadowJar.mergeServiceFiles();
});
// Add "original" classifier to the non-shadowed JAR to distinguish it from the shadow JAR
project.getTasks().named(JavaPlugin.JAR_TASK_NAME, Jar.class).configure(jar -> jar.getArchiveClassifier().set("original"));
// Make sure we assemble the shadow jar
project.getTasks().named(BasePlugin.ASSEMBLE_TASK_NAME).configure(task -> task.dependsOn("shadowJar"));
});
}
use of com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar 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));
}
});
}
}
use of com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar in project ehcache3 by ehcache.
the class PackagePlugin method createPackage.
private void createPackage(Project project, Optional<VariantPlugin.Variant> variant) {
String name = variant.map(VariantPlugin.Variant::getName).orElse(null);
ServiceRegistry projectServices = ((ProjectInternal) project).getServices();
JvmPluginServices jvmPluginServices = projectServices.get(JvmPluginServices.class);
ConfigurationBucketSet packageBuckets = ConfigurationBucketSet.bucketsFor(project, name, CONTENTS_KIND);
Configuration contentsCompileClasspath = jvmPluginServices.createResolvableConfiguration(lower(camel(name, CONTENTS_KIND, COMPILE_CLASSPATH_CONFIGURATION_NAME)), builder -> builder.extendsFrom(packageBuckets.bucket(CONTENTS_KIND)).requiresJavaLibrariesAPI());
Configuration contentsRuntimeClasspath = jvmPluginServices.createResolvableConfiguration(lower(camel(name, CONTENTS_KIND, RUNTIME_CLASSPATH_CONFIGURATION_NAME)), builder -> builder.extendsFrom(packageBuckets.bucket(CONTENTS_KIND)).requiresJavaLibrariesRuntime());
Configuration contentsSourcesFiles = jvmPluginServices.createResolvableConfiguration(lower(camel(name, CONTENTS_KIND, "sourcesFiles")), builder -> builder.extendsFrom(packageBuckets.bucket(CONTENTS_KIND)).requiresAttributes(refiner -> refiner.documentation(SOURCES)));
TaskProvider<ShadowJar> shadowJar = project.getTasks().register(lower(camel(name, "jar")), ShadowJar.class, shadow -> {
shadow.setGroup(BasePlugin.BUILD_GROUP);
shadow.getArchiveClassifier().set(name);
shadow.setConfigurations(Collections.singletonList(contentsRuntimeClasspath));
shadow.relocate("org.terracotta.statistics.", "org.ehcache.shadow.org.terracotta.statistics.");
shadow.relocate("org.terracotta.offheapstore.", "org.ehcache.shadow.org.terracotta.offheapstore.");
shadow.relocate("org.terracotta.context.", "org.ehcache.shadow.org.terracotta.context.");
shadow.relocate("org.terracotta.utilities.", "org.ehcache.shadow.org.terracotta.utilities.");
shadow.mergeServiceFiles();
shadow.exclude("META-INF/MANIFEST.MF", "LICENSE", "NOTICE");
// LICENSE is included in root gradle build
shadow.from(new File(project.getRootDir(), "NOTICE"));
shadow.setDuplicatesStrategy(DuplicatesStrategy.EXCLUDE);
});
Configuration apiElements = jvmPluginServices.createOutgoingElements(lower(camel(name, API_ELEMENTS_CONFIGURATION_NAME)), builder -> builder.extendsFrom(packageBuckets.api()).extendsFrom(packageBuckets.compileOnlyApi()).published().providesApi().artifact(shadowJar));
configureDefaultTargetPlatform(apiElements, 8);
Configuration compileClasspath = jvmPluginServices.createResolvableConfiguration(lower(camel(name, COMPILE_CLASSPATH_CONFIGURATION_NAME)), builder -> builder.extendsFrom(packageBuckets.implementation()).extendsFrom(packageBuckets.compileOnly()).requiresJavaLibrariesRuntime());
Configuration runtimeElements = jvmPluginServices.createOutgoingElements(lower(camel(name, RUNTIME_ELEMENTS_CONFIGURATION_NAME)), builder -> builder.extendsFrom(packageBuckets.implementation()).extendsFrom(packageBuckets.runtimeOnly()).published().providesRuntime().artifact(shadowJar));
configureDefaultTargetPlatform(runtimeElements, 8);
Configuration runtimeClasspath = jvmPluginServices.createResolvableConfiguration(lower(camel(name, RUNTIME_CLASSPATH_CONFIGURATION_NAME)), builder -> builder.extendsFrom(packageBuckets.implementation()).extendsFrom(packageBuckets.runtimeOnly()).requiresJavaLibrariesRuntime());
Provider<FileCollection> sourcesTree = project.provider(() -> contentsSourcesFiles.getResolvedConfiguration().getLenientConfiguration().getAllModuleDependencies().stream().flatMap(d -> d.getModuleArtifacts().stream()).map(artifact -> {
try {
return Optional.of(artifact.getFile());
} catch (ArtifactResolveException e) {
return Optional.<File>empty();
}
}).filter(Optional::isPresent).map(Optional::get).distinct().map(file -> {
if (file.isFile()) {
return project.zipTree(file);
} else {
return project.fileTree(file);
}
}).reduce(FileTree::plus).orElse(project.files().getAsFileTree()));
TaskProvider<Sync> sources = project.getTasks().register(lower(camel(name, "sources")), Sync.class, sync -> {
sync.dependsOn(contentsSourcesFiles);
sync.from(sourcesTree, spec -> spec.exclude("META-INF/**", "LICENSE", "NOTICE"));
sync.into(project.getLayout().getBuildDirectory().dir(lower(camel(name, "sources"))));
});
TaskProvider<Jar> sourcesJar = project.getTasks().register(lower(camel(name, "sourcesJar")), Jar.class, jar -> {
jar.setGroup(BasePlugin.BUILD_GROUP);
jar.from(sources);
jar.from(shadowJar, spec -> spec.include("META-INF/**", "LICENSE", "NOTICE"));
jar.getArchiveClassifier().set(kebab(name, "sources"));
});
Configuration sourcesElements = jvmPluginServices.createOutgoingElements(lower(camel(name, SOURCES_ELEMENTS_CONFIGURATION_NAME)), builder -> builder.published().artifact(sourcesJar).providesAttributes(attributes -> attributes.documentation(SOURCES).asJar()));
TaskProvider<Javadoc> javadoc = project.getTasks().register(lower(camel(name, "javadoc")), Javadoc.class, task -> {
task.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP);
task.setTitle(project.getName() + " " + project.getVersion() + " API");
task.source(sources);
task.include("**/*.java");
task.setClasspath(contentsCompileClasspath.plus(compileClasspath));
task.setDestinationDir(new File(project.getBuildDir(), "docs/" + lower(camel(name, "javadoc"))));
});
TaskProvider<Jar> javadocJar = project.getTasks().register(lower(camel(name, "javadocJar")), Jar.class, jar -> {
jar.setGroup(BasePlugin.BUILD_GROUP);
jar.from(javadoc);
jar.getArchiveClassifier().set(kebab(name, "javadoc"));
});
Configuration javadocElements = jvmPluginServices.createOutgoingElements(lower(camel(name, JAVADOC_ELEMENTS_CONFIGURATION_NAME)), builder -> builder.published().artifact(javadocJar).providesAttributes(attributes -> attributes.documentation(JAVADOC).asJar()));
shadowJar.configure(shadow -> {
OsgiManifestJarExtension osgiExtension = new OsgiManifestJarExtension(shadow);
osgiExtension.getClasspath().from(runtimeClasspath);
osgiExtension.getSources().from(sources);
BndConvention.bundleDefaults(project).execute(osgiExtension.getInstructions());
});
project.getComponents().named("java", AdhocComponentWithVariants.class, java -> {
java.addVariantsFromConfiguration(apiElements, variantDetails -> {
variantDetails.mapToMavenScope("compile");
variant.ifPresent(v -> variantDetails.mapToOptional());
});
java.addVariantsFromConfiguration(runtimeElements, variantDetails -> {
variantDetails.mapToMavenScope("runtime");
variant.ifPresent(v -> variantDetails.mapToOptional());
});
java.addVariantsFromConfiguration(sourcesElements, variantDetails -> {
});
java.addVariantsFromConfiguration(javadocElements, variantDetails -> {
});
});
if (variant.isPresent()) {
VariantPlugin.Variant v = variant.get();
ConfigurationBucketSet commonBuckets = ConfigurationBucketSet.bucketsFor(project, COMMON_KIND, CONTENTS_KIND);
packageBuckets.extendFrom(commonBuckets);
v.getConfigTraits().configureEach(trait -> packageBuckets.extendFrom(ConfigurationBucketSet.bucketsFor(project, camel(trait, "trait"))));
v.getCapabilities().configureEach(capability -> {
apiElements.getOutgoing().capability(capability);
runtimeElements.getOutgoing().capability(capability);
sourcesElements.getOutgoing().capability(capability);
javadocElements.getOutgoing().capability(capability);
});
} else {
project.getPlugins().withType(VariantPlugin.class).configureEach(variantPlugin -> {
project.getExtensions().configure(VariantPlugin.VariantExtension.class, variants -> {
VariantPlugin.Variant v = variants.getDefaultVariant();
ConfigurationBucketSet commonBuckets = ConfigurationBucketSet.bucketsFor(project, COMMON_KIND, CONTENTS_KIND);
packageBuckets.extendFrom(commonBuckets);
v.getConfigTraits().configureEach(trait -> packageBuckets.extendFrom(ConfigurationBucketSet.bucketsFor(project, camel(trait, "trait"))));
v.getCapabilities().configureEach(capability -> {
apiElements.getOutgoing().capability(capability);
runtimeElements.getOutgoing().capability(capability);
sourcesElements.getOutgoing().capability(capability);
javadocElements.getOutgoing().capability(capability);
});
});
});
}
project.getTasks().named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME).configure(task -> {
task.dependsOn(shadowJar);
task.dependsOn(javadocJar);
task.dependsOn(sourcesJar);
});
}
Aggregations