added jlink plugin
This commit is contained in:
@@ -38,7 +38,7 @@ subprojects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wrapper {
|
wrapper {
|
||||||
gradleVersion = "7.0.2"
|
gradleVersion = "7.1.1"
|
||||||
distributionType = Wrapper.DistributionType.ALL
|
distributionType = Wrapper.DistributionType.ALL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,7 +0,0 @@
|
|||||||
repositories {
|
|
||||||
jcenter()
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins {
|
|
||||||
`kotlin-dsl`
|
|
||||||
}
|
|
@@ -1,5 +0,0 @@
|
|||||||
import org.gradle.api.Project
|
|
||||||
|
|
||||||
operator fun Project.get(key : String) : String? {
|
|
||||||
return property(key) as String?
|
|
||||||
}
|
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
15
jlink/build.gradle
Normal file
15
jlink/build.gradle
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
plugins {
|
||||||
|
id 'maven-publish'
|
||||||
|
id 'java-gradle-plugin'
|
||||||
|
}
|
||||||
|
|
||||||
|
version = "0.1"
|
||||||
|
|
||||||
|
gradlePlugin {
|
||||||
|
plugins {
|
||||||
|
create("JlinkPlugin") {
|
||||||
|
id = "net.woggioni.gradle.jlink"
|
||||||
|
implementationClass = "net.woggioni.gradle.jlink.JlinkPlugin"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,11 @@
|
|||||||
|
package net.woggioni.gradle.jlink;
|
||||||
|
|
||||||
|
import org.gradle.api.Plugin;
|
||||||
|
import org.gradle.api.Project;
|
||||||
|
|
||||||
|
public class JlinkPlugin implements Plugin<Project> {
|
||||||
|
@Override
|
||||||
|
public void apply(Project project) {
|
||||||
|
project.getTasks().register("jlink", JlinkTask.class);
|
||||||
|
}
|
||||||
|
}
|
122
jlink/src/main/java/net/woggioni/gradle/jlink/JlinkTask.java
Normal file
122
jlink/src/main/java/net/woggioni/gradle/jlink/JlinkTask.java
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
package net.woggioni.gradle.jlink;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import org.apache.tools.ant.taskdefs.condition.Os;
|
||||||
|
import org.gradle.api.DefaultTask;
|
||||||
|
import org.gradle.api.GradleException;
|
||||||
|
import org.gradle.api.file.DirectoryProperty;
|
||||||
|
import org.gradle.api.file.FileCollection;
|
||||||
|
import org.gradle.api.model.ObjectFactory;
|
||||||
|
import org.gradle.api.plugins.*;
|
||||||
|
import org.gradle.api.provider.ListProperty;
|
||||||
|
import org.gradle.api.provider.Property;
|
||||||
|
import org.gradle.api.provider.Provider;
|
||||||
|
import org.gradle.api.tasks.*;
|
||||||
|
import org.gradle.jvm.toolchain.JavaInstallationMetadata;
|
||||||
|
import org.gradle.jvm.toolchain.JavaLauncher;
|
||||||
|
import org.gradle.jvm.toolchain.JavaToolchainService;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public class JlinkTask extends DefaultTask {
|
||||||
|
|
||||||
|
@Getter(onMethod_ = {@Input, @Optional} )
|
||||||
|
private final Property<String> launcher;
|
||||||
|
|
||||||
|
@Getter(onMethod_ = {@Input, @Optional} )
|
||||||
|
private final Property<String> mainClass;
|
||||||
|
|
||||||
|
@Getter(onMethod_ = {@Input} )
|
||||||
|
private final Property<String> mainModule;
|
||||||
|
|
||||||
|
@Getter(onMethod_ = {@Input} )
|
||||||
|
private final ListProperty<String> rootModules;
|
||||||
|
|
||||||
|
@Getter(onMethod_ = {@OutputDirectory} )
|
||||||
|
private final DirectoryProperty destination;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter(onMethod_ = {@InputFiles} )
|
||||||
|
private FileCollection modulePath;
|
||||||
|
|
||||||
|
private final Provider<JavaLauncher> javaLauncher;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public JlinkTask(@Nonnull ObjectFactory objectFactory) {
|
||||||
|
ExtensionContainer ext = getProject().getExtensions();
|
||||||
|
mainClass = objectFactory.property(String.class).convention(ext.findByType(JavaApplication.class).getMainClass());
|
||||||
|
mainModule = objectFactory.property(String.class).convention(ext.findByType(JavaApplication.class).getMainModule());
|
||||||
|
launcher = objectFactory.property(String.class).convention(getProject().provider(() -> {
|
||||||
|
String source;
|
||||||
|
if(mainClass.isPresent()) {
|
||||||
|
source = mainClass.get();
|
||||||
|
} else {
|
||||||
|
source = mainModule.get();
|
||||||
|
}
|
||||||
|
int i = source.lastIndexOf(".");
|
||||||
|
return source.substring(i == -1 ? 0 : i);
|
||||||
|
}));
|
||||||
|
rootModules = objectFactory.listProperty(String.class).convention(getProject().provider(() -> Arrays.asList(mainModule.get())));
|
||||||
|
modulePath = getProject().getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME)
|
||||||
|
.plus(getProject().getTasks().named(JavaPlugin.JAR_TASK_NAME).get().getOutputs().getFiles());
|
||||||
|
|
||||||
|
destination = objectFactory.directoryProperty().convention(
|
||||||
|
ext.findByType(BasePluginExtension.class)
|
||||||
|
.getDistsDirectory()
|
||||||
|
.map(it -> it.dir(getProject().getName()))
|
||||||
|
);
|
||||||
|
|
||||||
|
JavaToolchainService javaToolchainService = ext.findByType(JavaToolchainService.class);
|
||||||
|
JavaPluginExtension javaPluginExtension = ext.findByType(JavaPluginExtension.class);
|
||||||
|
javaLauncher = objectFactory.property(JavaLauncher.class)
|
||||||
|
.convention(javaToolchainService.launcherFor(javaPluginExtension.getToolchain()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
@TaskAction
|
||||||
|
public void run() {
|
||||||
|
File javaHome;
|
||||||
|
if(javaLauncher.isPresent()) {
|
||||||
|
JavaInstallationMetadata javaInstallationMetadata = javaLauncher.get().getMetadata();
|
||||||
|
if (!javaInstallationMetadata.getLanguageVersion().canCompileOrRun(9)) {
|
||||||
|
throw new GradleException(String.format("Minimum Java version supported by '%s' is 9", JlinkTask.class.getName()));
|
||||||
|
}
|
||||||
|
javaHome = javaInstallationMetadata.getInstallationPath().getAsFile();
|
||||||
|
} else {
|
||||||
|
javaHome = new File(System.getProperty("java.home"));
|
||||||
|
}
|
||||||
|
String executableFileExtension;
|
||||||
|
if(Os.isFamily(Os.FAMILY_WINDOWS)) {
|
||||||
|
executableFileExtension = ".exe";
|
||||||
|
} else {
|
||||||
|
executableFileExtension = "";
|
||||||
|
}
|
||||||
|
String jlinkPath = new File(javaHome, "bin/jlink" + executableFileExtension).getPath();
|
||||||
|
|
||||||
|
List<String> cmd = new ArrayList<>();
|
||||||
|
cmd.add(jlinkPath);
|
||||||
|
cmd.add("--module-path");
|
||||||
|
cmd.add(modulePath.getAsPath());
|
||||||
|
for(String moduleName : rootModules.get()) {
|
||||||
|
cmd.add("--add-modules");
|
||||||
|
cmd.add(moduleName);
|
||||||
|
}
|
||||||
|
cmd.add("--launcher");
|
||||||
|
if(mainClass.isPresent()) {
|
||||||
|
cmd.add(String.format("%s=%s/%s", launcher.get(), mainModule.get(), mainClass.get()));
|
||||||
|
} else {
|
||||||
|
cmd.add(String.format("%s=%s", launcher.get(), mainModule.get()));
|
||||||
|
}
|
||||||
|
cmd.add("--output");
|
||||||
|
cmd.add(destination.get().getAsFile().getPath());
|
||||||
|
getProject().exec(execSpec -> execSpec.commandLine(cmd));
|
||||||
|
}
|
||||||
|
}
|
@@ -24,7 +24,8 @@ public class LombokPlugin implements Plugin<Project> {
|
|||||||
ObjectFactory objectFactory = project.getObjects();
|
ObjectFactory objectFactory = project.getObjects();
|
||||||
LombokExtension ext = project.getExtensions()
|
LombokExtension ext = project.getExtensions()
|
||||||
.create("lombok", LombokExtension.class,
|
.create("lombok", LombokExtension.class,
|
||||||
objectFactory.property(String.class).convention("1.18.20")
|
objectFactory.property(String.class)
|
||||||
|
.convention((String) project.getExtensions().getExtraProperties().get("version.lombok"))
|
||||||
);
|
);
|
||||||
JavaPluginConvention javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
|
JavaPluginConvention javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
|
||||||
SourceSetContainer sourceSetContainer = javaPluginConvention.getSourceSets();
|
SourceSetContainer sourceSetContainer = javaPluginConvention.getSourceSets();
|
||||||
|
@@ -16,3 +16,4 @@ include("jpms-check")
|
|||||||
include("multi-release-jar")
|
include("multi-release-jar")
|
||||||
include("wildfly")
|
include("wildfly")
|
||||||
include("lombok")
|
include("lombok")
|
||||||
|
include("jlink")
|
||||||
|
Reference in New Issue
Block a user