Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Shadow Jar Source #156

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

buildscript {
repositories {
gradlePluginPortal()
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}

dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
classpath 'com.github.johnrengelman.shadow:com.github.johnrengelman.shadow.gradle.plugin:7.1.2'
classpath 'com.github.alisiikh:gradle-scalastyle-plugin:3.4.1'
classpath "io.github.gradle-nexus:publish-plugin:1.0.0"
classpath "org.shipkit:shipkit-auto-version:1.1.1"
Expand Down
3 changes: 2 additions & 1 deletion transportable-udfs-examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ allprojects {
subprojects {
buildscript {
repositories {
mavenCentral()
gradlePluginPortal()
jcenter()
mavenCentral()
}
}
repositories {
Expand Down
6 changes: 5 additions & 1 deletion transportable-udfs-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ plugins {
id 'signing'
}

repositories {
gradlePluginPortal()
}

dependencies {
implementation project(':transportable-udfs-api')
implementation project(':transportable-udfs-codegen')
implementation ('com.google.guava:guava:24.1-jre')
implementation ('com.google.code.gson:gson:2.8.5')
implementation ('com.github.jengelman.gradle.plugins:shadow:5.2.0')
implementation ('com.github.johnrengelman.shadow:com.github.johnrengelman.shadow.gradle.plugin:7.1.2')
testImplementation('org.spockframework:spock-core:1.1-groovy-2.4') {
exclude group: 'org.codehaus.groovy'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void apply(Project project) {
project.getPlugins().withType(JavaPlugin.class, (javaPlugin) -> {
project.getPlugins().apply(ScalaPlugin.class);
project.getPlugins().apply(DistributionPlugin.class);
project.getConfigurations().create(ShadowBasePlugin.getCONFIGURATION_NAME());
project.getConfigurations().create(ShadowBasePlugin.CONFIGURATION_NAME);

JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(extension.mainSourceSetName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public List<TaskProvider<? extends Task>> configurePackagingTasks(Project projec
// Explicitly set classifiers for the created distributions or else leads to Maven packaging issues due to multiple
// artifacts with the same classifier
project.getTasks().named(platform.getName() + "DistTar", Tar.class, tar -> tar.setClassifier(platform.getName()));
project.getArtifacts().add(ShadowBasePlugin.getCONFIGURATION_NAME(), project.getTasks().named(platform.getName() + "DistTar", Tar.class));
project.getArtifacts().add(ShadowBasePlugin.CONFIGURATION_NAME, project.getTasks().named(platform.getName() + "DistTar", Tar.class));
project.getTasks().named(platform.getName() + "DistZip", Zip.class, zip -> zip.setClassifier(platform.getName()));
project.getArtifacts().add(ShadowBasePlugin.getCONFIGURATION_NAME(), project.getTasks().named(platform.getName() + "DistZip", Zip.class));
project.getArtifacts().add(ShadowBasePlugin.CONFIGURATION_NAME, project.getTasks().named(platform.getName() + "DistZip", Zip.class));
return ImmutableList.of(project.getTasks().named(platform.getName() + "DistTar", Tar.class),
project.getTasks().named(platform.getName() + "DistZip", Zip.class));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private TaskProvider<ShadeTask> createShadeTask(Project project, Platform platfo
SourceSet mainSourceSet) {
TaskProvider<ShadeTask> shadeTask =
project.getTasks().register(sourceSet.getTaskName("shade", "Jar"), ShadeTask.class, task -> {
task.setGroup(ShadowJavaPlugin.getSHADOW_GROUP());
task.setGroup(ShadowJavaPlugin.SHADOW_GROUP);
task.setDescription("Create a combined JAR of " + platform.getName() + " output and runtime dependencies");
task.setClassifier(platform.getName());
task.getManifest()
Expand All @@ -79,7 +79,7 @@ private TaskProvider<ShadeTask> createShadeTask(Project project, Platform platfo
task.exclude("META-INF/INDEX.LIST", "META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA");
});

String configuration = ShadowBasePlugin.getCONFIGURATION_NAME();
String configuration = ShadowBasePlugin.CONFIGURATION_NAME;
project.getArtifacts().add(configuration, shadeTask);
AdhocComponentWithVariants java = project.getComponents().withType(AdhocComponentWithVariants.class).getByName("java");
java.addVariantsFromConfiguration(project.getConfigurations().getByName(configuration), v -> v.mapToOptional());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ public List<TaskProvider<? extends Task>> configurePackagingTasks(Project projec
task.from(platformSourceSet.getOutput());
task.from(platformSourceSet.getResources());
});

String configuration = ShadowBasePlugin.getCONFIGURATION_NAME();
project.getArtifacts().add(configuration, thinJarTask);

project.getArtifacts().add(ShadowBasePlugin.CONFIGURATION_NAME, thinJarTask);
AdhocComponentWithVariants java = project.getComponents().withType(AdhocComponentWithVariants.class).getByName("java");
java.addVariantsFromConfiguration(project.getConfigurations().getByName(configuration), v -> v.mapToOptional());
java.addVariantsFromConfiguration(project.getConfigurations().getByName(ShadowBasePlugin.CONFIGURATION_NAME), v -> v.mapToOptional());

return ImmutableList.of(thinJarTask);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/
package com.linkedin.transport.plugin.tasks;

import com.github.jengelman.gradle.plugins.shadow.relocation.RelocateClassContext;
import com.github.jengelman.gradle.plugins.shadow.relocation.RelocatePathContext;
import com.github.jengelman.gradle.plugins.shadow.relocation.SimpleRelocator;
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -107,7 +105,7 @@ protected void copy() {
Set<String> classPathsToShade = new HashSet<>();

List<Configuration> configurations =
getConfigurations().stream().map(this::setupConfiguration).collect(Collectors.toList());
getConfigurations().stream().map(files -> this.setupConfiguration((Configuration) files)).collect(Collectors.toList());

// Collect all classes which need to be shaded
configurations.forEach(configuration -> classPathsToShade.addAll(classesInConfiguration(configuration)));
Expand All @@ -119,21 +117,24 @@ protected void copy() {
Set<String> classNamesToShade =
classPathsToShade.stream().map(path -> path.replace('/', '.')).collect(Collectors.toSet());
// Pass the new updated conf to _shadowJar
setConfigurations(configurations);
setConfigurations(ImmutableList.copyOf(configurations));
// Exclude source files
exclude("**/*.java");
// Do not shade classes we have excluded
_doNotShade = ImmutableList.<String>builder().addAll(_doNotShade).addAll(getExcludes()).build();
// Relocate base on the above restrictions
super.relocate(new SimpleRelocator(null, _shadePrefix + '/', ImmutableList.of("**"), _doNotShade) {
public boolean canRelocatePath(RelocatePathContext context) {
@Override
public boolean canRelocatePath(String path) {
// Only relocate those classes present in source project and dependency jars
return classPathsToShade.contains(context.getPath()) && super.canRelocatePath(context);
return classPathsToShade.contains(path) && super.canRelocatePath(path);
}

public boolean canRelocateClass(RelocateClassContext context) {
@Override

public boolean canRelocateClass(String className) {
// Only relocate those classes present in source project and dependency jars
return classNamesToShade.contains(context.getClassName()) && super.canRelocateClass(context);
return classNamesToShade.contains(className) && super.canRelocateClass(className);
}
});
super.copy();
Expand Down Expand Up @@ -204,4 +205,4 @@ private static Set<String> classesInJar(File jar) {
}
return classes;
}
}
}