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

Detect shadow jar for run task #26

Merged
merged 1 commit into from
May 28, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ private Dependencies() {
}
}

public static final class Plugins {
public static final String SHADOW_PLUGIN_ID = "com.github.johnrengelman.shadow";
public static final String SHADOW_JAR_TASK_NAME = "shadowJar";

private Plugins() {
}
}

private Constants() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.gradle.api.Action;
import org.gradle.api.NamedDomainObjectCollection;
import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.NamedDomainObjectProvider;
import org.gradle.api.Plugin;
Expand All @@ -38,7 +37,6 @@
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
import org.gradle.api.artifacts.result.ResolvedArtifactResult;
import org.gradle.api.file.Directory;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.FileCollection;
import org.gradle.api.plugins.JavaLibraryPlugin;
import org.gradle.api.plugins.JavaPlugin;
Expand All @@ -48,7 +46,7 @@
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.jvm.tasks.Jar;
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
import org.gradle.process.CommandLineArgumentProvider;
import org.spongepowered.gradle.common.Constants;
import org.spongepowered.gradle.common.SpongePlatform;
Expand Down Expand Up @@ -221,13 +219,18 @@ public void execute(final Task a) {
});
});

this.project.getPlugins().withType(JavaPlugin.class, v -> {
// TODO: Use shadow jar here if that plugin is applied
final TaskProvider<?> jarTask = this.project.getTasks().named(JavaPlugin.JAR_TASK_NAME);
this.project.afterEvaluate(p -> {
final TaskProvider<AbstractArchiveTask> archiveTask;
if (p.getPlugins().hasPlugin(Constants.Plugins.SHADOW_PLUGIN_ID)) {
archiveTask = p.getTasks().named(Constants.Plugins.SHADOW_JAR_TASK_NAME, AbstractArchiveTask.class);
} else {
archiveTask = p.getTasks().named(JavaPlugin.JAR_TASK_NAME, AbstractArchiveTask.class);
}
runServer.configure(new Action<JavaExec>() {
@Override
public void execute(final JavaExec it) {
it.classpath(jarTask);
it.dependsOn(archiveTask);
it.classpath(archiveTask.map(AbstractArchiveTask::getArchiveFile));
}
}); // TODO: is there a sensible way to run without the jar?
});
Expand Down