version update and improved MultiVersionJarPlugin
This commit is contained in:
27
build.gradle
27
build.gradle
@@ -1,6 +1,31 @@
|
||||
subprojects {
|
||||
subprojects { subproject ->
|
||||
apply plugin: 'java-library'
|
||||
|
||||
version = getProperty('version.myGradlePlugins')
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(11)
|
||||
}
|
||||
}
|
||||
|
||||
int javaVersion
|
||||
if(subproject.path == ':osgi-app') {
|
||||
javaVersion = 11
|
||||
} else {
|
||||
javaVersion = 8
|
||||
}
|
||||
tasks.named(JavaPlugin.COMPILE_JAVA_TASK_NAME, JavaCompile) {
|
||||
options.release = javaVersion
|
||||
options.compilerArgs << '-parameters'
|
||||
}
|
||||
|
||||
pluginManager.withPlugin('groovy') {
|
||||
tasks.named("compileGroovy", GroovyCompile) {
|
||||
options.release = javaVersion
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url = woggioniMavenRepositoryUrl
|
||||
|
@@ -5,11 +5,6 @@ plugins {
|
||||
dependencies {
|
||||
}
|
||||
|
||||
compileJava {
|
||||
options.release = 8
|
||||
options.compilerArgs << '-parameters'
|
||||
}
|
||||
|
||||
["apiElements", "runtimeElements"].each { String name ->
|
||||
def conf = project.configurations.getByName(name)
|
||||
conf.attributes {
|
||||
@@ -17,8 +12,6 @@ compileJava {
|
||||
}
|
||||
}
|
||||
|
||||
version = 0.2
|
||||
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
create("DependencyExportPlugin") {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
woggioniMavenRepositoryUrl=https://mvn.woggioni.net/
|
||||
|
||||
version.myGraglePlugins=2021.10
|
||||
version.gradle=7.3.3
|
||||
version.myGradlePlugins=2022.06
|
||||
version.gradle=7.4.3
|
||||
version.lombok=1.18.16
|
||||
version.junitJupiter=5.7.2
|
||||
version.junitPlatform=1.7.0
|
||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
@@ -3,13 +3,6 @@ plugins {
|
||||
id 'java-gradle-plugin'
|
||||
}
|
||||
|
||||
version = "0.1"
|
||||
|
||||
compileJava {
|
||||
options.release = 8
|
||||
options.compilerArgs << '-parameters'
|
||||
}
|
||||
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
create("JlinkPlugin") {
|
||||
|
@@ -2,8 +2,6 @@ plugins {
|
||||
id 'groovy-gradle-plugin'
|
||||
}
|
||||
|
||||
version = "0.1"
|
||||
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
create("JPMSCheckPlugin") {
|
||||
@@ -12,8 +10,3 @@ gradlePlugin {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
compileJava {
|
||||
options.release = 8
|
||||
options.compilerArgs << '-parameters'
|
||||
}
|
||||
|
@@ -2,13 +2,6 @@ plugins {
|
||||
id 'java-gradle-plugin'
|
||||
}
|
||||
|
||||
version = "0.1"
|
||||
|
||||
compileJava {
|
||||
options.release = 8
|
||||
options.compilerArgs << '-parameters'
|
||||
}
|
||||
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
create("LombokPlugin") {
|
||||
|
@@ -3,8 +3,6 @@ plugins {
|
||||
id 'groovy-gradle-plugin'
|
||||
}
|
||||
|
||||
version = "0.1"
|
||||
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
create("MultiVersionJarPlugin") {
|
||||
@@ -17,8 +15,3 @@ gradlePlugin {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
compileJava {
|
||||
options.release = 8
|
||||
options.compilerArgs << '-parameters'
|
||||
}
|
||||
|
@@ -1,79 +0,0 @@
|
||||
package net.woggioni.gradle.multi.release.jar
|
||||
|
||||
import org.gradle.api.JavaVersion
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.Configuration
|
||||
import org.gradle.api.attributes.java.TargetJvmVersion
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.file.SourceDirectorySet
|
||||
import org.gradle.api.plugins.JavaBasePlugin
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.SourceSet
|
||||
import org.gradle.api.tasks.compile.JavaCompile
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
|
||||
class MultiVersionJarPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
void apply(Project project) {
|
||||
project.apply(to: JavaBasePlugin)
|
||||
if(JavaVersion.current() > JavaVersion.VERSION_1_8) {
|
||||
SourceSet mainSourceSet = (project.sourceSets.main as SourceSet)
|
||||
SourceDirectorySet javaSet = mainSourceSet.java
|
||||
File java8ClassesDir = project.buildDir.toPath().resolve("classes/java8").toFile()
|
||||
File java11ClassesDir = project.buildDir.toPath().resolve("classes/java11").toFile()
|
||||
JavaCompile compileJava8Task = project.tasks.register("compileJava8", JavaCompile, {
|
||||
exclude("module-info.java")
|
||||
options.release = JavaVersion.VERSION_1_8.majorVersion.toInteger()
|
||||
classpath = mainSourceSet.compileClasspath
|
||||
source = javaSet
|
||||
destinationDirectory = java8ClassesDir
|
||||
options.annotationProcessorPath = mainSourceSet.annotationProcessorPath
|
||||
modularity.inferModulePath = false
|
||||
}).get()
|
||||
|
||||
JavaCompile compileModuleInfoTask = project.tasks.register("compileModuleInfo", JavaCompile, {
|
||||
include("module-info.java")
|
||||
options.release = JavaVersion.VERSION_11.majorVersion.toInteger()
|
||||
classpath = mainSourceSet.compileClasspath
|
||||
source = (project.sourceSets.main as SourceSet).java
|
||||
destinationDirectory = java11ClassesDir
|
||||
options.annotationProcessorPath = mainSourceSet.annotationProcessorPath
|
||||
modularity.inferModulePath = true
|
||||
}).get()
|
||||
|
||||
Provider<Jar> jarTaskProvider = project.tasks.named("jar", Jar)
|
||||
Provider<Jar> multiVersionJarTaskProvider = project.tasks.register("multiVersionJar", Jar) {
|
||||
Jar jarTask = jarTaskProvider.get()
|
||||
from(compileJava8Task.outputs.files)
|
||||
from(compileModuleInfoTask.outputs.files)
|
||||
archiveBaseName = jarTask.archiveBaseName
|
||||
destinationDirectory = jarTask.destinationDirectory
|
||||
archiveExtension = jarTask.archiveExtension
|
||||
manifest = jarTask.manifest
|
||||
}
|
||||
|
||||
jarTaskProvider.configure {
|
||||
actions = []
|
||||
Jar multiVersionJarTask = multiVersionJarTaskProvider.get()
|
||||
from(multiVersionJarTask.outputs.files)
|
||||
(it.archiveFile as RegularFileProperty).set(multiVersionJarTask.archiveFile)
|
||||
}
|
||||
["apiElements", "runtimeElements"].forEach {String name ->
|
||||
Configuration conf = project.configurations.getByName(name)
|
||||
conf.attributes {
|
||||
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 8)
|
||||
}
|
||||
}
|
||||
}
|
||||
project.tasks.named("compileJava", JavaCompile) {
|
||||
if(JavaVersion.current() > JavaVersion.VERSION_1_8) {
|
||||
modularity.inferModulePath = true
|
||||
} else {
|
||||
exclude("module-info.java")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,152 @@
|
||||
package net.woggioni.gradle.multi.release.jar;
|
||||
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.GradleException;
|
||||
import org.gradle.api.JavaVersion;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.Task;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.artifacts.ConfigurationContainer;
|
||||
import org.gradle.api.attributes.LibraryElements;
|
||||
import org.gradle.api.file.FileCollection;
|
||||
import org.gradle.api.model.ObjectFactory;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.plugins.JavaPluginExtension;
|
||||
import org.gradle.api.provider.Property;
|
||||
import org.gradle.api.provider.Provider;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.tasks.SourceSetContainer;
|
||||
import org.gradle.api.tasks.TaskContainer;
|
||||
import org.gradle.api.tasks.TaskProvider;
|
||||
import org.gradle.api.tasks.compile.CompileOptions;
|
||||
import org.gradle.api.tasks.compile.JavaCompile;
|
||||
import org.gradle.jvm.tasks.Jar;
|
||||
import org.gradle.jvm.toolchain.JavaLanguageVersion;
|
||||
import org.gradle.jvm.toolchain.JavaToolchainSpec;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.gradle.api.attributes.LibraryElements.JAR;
|
||||
import static org.gradle.api.attributes.LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE;
|
||||
|
||||
public class MultiVersionJarPlugin implements Plugin<Project> {
|
||||
|
||||
private void dop(Project project) {
|
||||
JavaPluginExtension javaExtension = project.getExtensions().getByType(JavaPluginExtension.class);
|
||||
JavaVersion binaryVersion =
|
||||
Optional.ofNullable(javaExtension.getToolchain())
|
||||
.map(JavaToolchainSpec::getLanguageVersion)
|
||||
.filter(Property<JavaLanguageVersion>::isPresent)
|
||||
.map(Property<JavaLanguageVersion>::get)
|
||||
.map(jls -> JavaVersion.toVersion(jls.toString()))
|
||||
.orElseGet(() -> Optional.ofNullable(
|
||||
javaExtension.getTargetCompatibility()).orElseGet(JavaVersion::current)
|
||||
);
|
||||
|
||||
if (JavaVersion.VERSION_1_8.compareTo(binaryVersion) < 0) {
|
||||
ObjectFactory objects = project.getObjects();
|
||||
TaskContainer tasks = project.getTasks();
|
||||
SourceSetContainer sourceSets = javaExtension.getSourceSets();
|
||||
ConfigurationContainer configurations = project.getConfigurations();
|
||||
configurations.named(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME, conf -> {
|
||||
conf.attributes(attrs -> {
|
||||
attrs.attribute(LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements.class, JAR));
|
||||
});
|
||||
});
|
||||
String[] lastConfigurationName = new String[] { JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME };
|
||||
SourceSet mainSourceSet = sourceSets.getByName("main");
|
||||
ArrayList<FileCollection> compileOutputs = new ArrayList<>();
|
||||
compileOutputs.add(tasks.getByName(mainSourceSet.getCompileJavaTaskName())
|
||||
.getOutputs().getFiles());
|
||||
ArrayList<FileCollection> sourcePaths = new ArrayList<>();
|
||||
sourcePaths.add(mainSourceSet.getJava().getSourceDirectories());
|
||||
Configuration compileClasspathConfiguration =
|
||||
configurations.getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME);
|
||||
|
||||
Provider<Jar> jarTaskProvider = tasks.named(JavaPlugin.JAR_TASK_NAME, Jar.class, jarTask -> {
|
||||
Map<String, String> m = Stream.of(
|
||||
new AbstractMap.SimpleEntry<>("Multi-Release", "true")
|
||||
).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
jarTask.getManifest().attributes(m);
|
||||
});
|
||||
|
||||
project.getTasks().named(JavaPlugin.COMPILE_JAVA_TASK_NAME, JavaCompile.class, t -> {
|
||||
t.exclude("module-info.java");
|
||||
t.getOptions().getRelease().set(Integer.parseInt(JavaVersion.VERSION_1_8.getMajorVersion()));
|
||||
});
|
||||
Arrays.stream(JavaVersion.values())
|
||||
.filter(v -> v.compareTo(JavaVersion.VERSION_1_8) > 0)
|
||||
.filter(v -> v.compareTo(binaryVersion) <= 0)
|
||||
.forEach(javaVersion -> {
|
||||
String sourceSetName = "java" + javaVersion.getMajorVersion();
|
||||
SourceSet sourceSet = sourceSets.create(sourceSetName);
|
||||
TaskProvider<JavaCompile> compileTask = tasks.register(
|
||||
JavaPlugin.COMPILE_JAVA_TASK_NAME + javaVersion.getMajorVersion(),
|
||||
JavaCompile.class,
|
||||
(JavaCompile javaCompileTask) -> {
|
||||
javaCompileTask.getOptions().getRelease().set(Integer.parseInt(javaVersion.getMajorVersion()));
|
||||
javaCompileTask.setClasspath(
|
||||
compileClasspathConfiguration.plus(compileOutputs.stream().reduce(FileCollection::plus)
|
||||
.orElseGet(project::files)));
|
||||
compileOutputs.add(javaCompileTask.getOutputs().getFiles());
|
||||
javaCompileTask.source(sourceSet.getAllJava().getSourceDirectories());
|
||||
javaCompileTask.getDestinationDirectory().set(sourceSet.getJava().getDestinationDirectory());
|
||||
javaCompileTask.getOptions().setAnnotationProcessorPath(sourceSet.getAnnotationProcessorPath());
|
||||
javaCompileTask.getModularity().getInferModulePath().set(javaExtension.getModularity().getInferModulePath());
|
||||
CompileOptions options = javaCompileTask.getOptions();
|
||||
options.setSourcepath(sourceSet.getJava().getSourceDirectories());
|
||||
// sourcePaths.stream()
|
||||
// .reduce(FileCollection::plus)
|
||||
// .ifPresent(options::setSourcepath);
|
||||
sourcePaths.add(sourceSet.getJava().getSourceDirectories());
|
||||
sourceSet.compiledBy(javaCompileTask);
|
||||
Optional<String> patchPath = compileOutputs.stream()
|
||||
.reduce(FileCollection::plus).map(FileCollection::getAsPath);
|
||||
|
||||
javaCompileTask.doFirst(new Action<Task>() {
|
||||
@Override
|
||||
public void execute(Task javaCompile) {
|
||||
if (project.hasProperty("jpms.module.name")) {
|
||||
patchPath.ifPresent(p -> {
|
||||
List<String> compilerArgs = javaCompileTask.getOptions().getCompilerArgs();
|
||||
compilerArgs.add("--patch-module");
|
||||
compilerArgs.add(project.property("jpms.module.name").toString() + '=' + p);
|
||||
});
|
||||
} else {
|
||||
throw new GradleException("Missing property 'jpms.module.name'");
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
tasks.named(JavaPlugin.JAR_TASK_NAME, Jar.class, jarTask -> {
|
||||
jarTask.from(compileTask.get().getDestinationDirectory(), cp -> {
|
||||
cp.into("META-INF/versions/" + javaVersion.getMajorVersion());
|
||||
});
|
||||
});
|
||||
|
||||
String extendFormConfiguration = lastConfigurationName[0];
|
||||
String confName = sourceSetName + JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME;
|
||||
lastConfigurationName[0] = confName;
|
||||
configurations.register(confName, conf -> {
|
||||
conf.attributes(attrs -> {
|
||||
attrs.attribute(LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements.class, JAR));
|
||||
});
|
||||
conf.extendsFrom(configurations.getByName(extendFormConfiguration));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
project.getPluginManager().withPlugin("java-library", plugin -> dop(project));
|
||||
}
|
||||
}
|
@@ -2,17 +2,10 @@ plugins {
|
||||
id "java-gradle-plugin"
|
||||
}
|
||||
|
||||
version = "0.1"
|
||||
|
||||
childProjects.forEach {name, child ->
|
||||
child.with {
|
||||
apply plugin: 'maven-publish'
|
||||
|
||||
compileJava {
|
||||
options.release = 8
|
||||
options.compilerArgs << '-parameters'
|
||||
}
|
||||
|
||||
publishing {
|
||||
repositories {
|
||||
maven {
|
||||
@@ -51,11 +44,6 @@ dependencies {
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
jar {
|
||||
into("META-INF") {
|
||||
from(configurations.embedded)
|
||||
|
@@ -3,7 +3,6 @@ plugins {
|
||||
}
|
||||
|
||||
group = "net.woggioni.osgi"
|
||||
version = "0.1"
|
||||
|
||||
dependencies {
|
||||
compileOnly group: 'org.osgi', name: 'osgi.annotation', version: getProperty('version.osgi')
|
||||
|
@@ -4,7 +4,6 @@ plugins {
|
||||
}
|
||||
|
||||
group = "net.woggioni.osgi"
|
||||
version = "0.1"
|
||||
|
||||
dependencies {
|
||||
compileOnly group: 'org.osgi', name: 'osgi.annotation', version: getProperty('version.osgi')
|
||||
|
@@ -3,7 +3,6 @@ plugins {
|
||||
}
|
||||
|
||||
group = "net.woggioni.osgi"
|
||||
version = "0.1"
|
||||
|
||||
configurations {
|
||||
tar {
|
||||
|
@@ -18,4 +18,3 @@ include 'osgi-app:osgi-simple-bootstrapper'
|
||||
include 'osgi-app:osgi-simple-bootstrapper-api'
|
||||
include 'osgi-app:osgi-simple-bootstrapper-application'
|
||||
include 'wildfly'
|
||||
include 'jlink'
|
||||
|
@@ -3,13 +3,6 @@ plugins {
|
||||
id 'java-gradle-plugin'
|
||||
}
|
||||
|
||||
version = "0.1"
|
||||
|
||||
compileJava {
|
||||
options.release = 8
|
||||
options.compilerArgs << '-parameters'
|
||||
}
|
||||
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
create("WildflyPlugin") {
|
||||
|
Reference in New Issue
Block a user