Skip to content

Commit

Permalink
a lot of nonsense
Browse files Browse the repository at this point in the history
  • Loading branch information
TropheusJ committed Jan 17, 2024
1 parent 93c6118 commit a660da0
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 14 deletions.
6 changes: 2 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ allprojects {
}
}

jar.from(rootProject.file("LICENSE")) // copy license file into jar

tasks.register("buildOrPublish") {
group = "build"
String mavenUser = System.getenv("MAVEN_USER")
Expand All @@ -136,10 +138,6 @@ allprojects {
println "prepared for build"
}
}

tasks.withType(AbstractArchiveTask).configureEach {
reproducibleFileOrder = true
}
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@
import com.google.gson.JsonParser;

import org.gradle.api.DefaultTask;
import org.gradle.api.file.ProjectLayout;
import org.gradle.api.file.RegularFile;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.OutputFiles;
import org.gradle.api.tasks.TaskAction;
import org.gradle.internal.impldep.bsh.commands.dir;
import org.gradle.jvm.tasks.Jar;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
Expand All @@ -24,10 +35,24 @@
import java.util.Set;
import java.util.stream.Stream;

public class DeduplicateInclusionsTask extends DefaultTask {
public abstract class DeduplicateInclusionsTask extends Jar {
private final RegularFileProperty duplicatedJar = getProject().getObjects().fileProperty();

@InputFile
public RegularFileProperty getDuplicatedJar() {
return this.duplicatedJar;
}

@TaskAction
public void deduplicateInclusions() {
getInputs().getFiles().forEach(builtJar -> deduplicateInclusions(builtJar.toPath()));
Path input = this.duplicatedJar.get().getAsFile().toPath();
Path output = this.getArchiveFile().get().getAsFile().toPath();
try {
Files.copy(input, output);
deduplicateInclusions(output);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public void deduplicateInclusions(Path jar) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.file.FileCollection;
import org.gradle.api.plugins.BasePlugin;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
import org.gradle.jvm.tasks.Jar;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down Expand Up @@ -40,13 +44,29 @@ public void setupValidation(Project project, Task validateModule) {
}

public void setupDeduplication(Project project) {
Task remapJar = project.getTasks().findByName("remapJar");
if (remapJar == null) {
throw new IllegalStateException("No remapJar task?");
}
Task deduplicateInclusions = project.getTasks().create("deduplicateInclusions", DeduplicateInclusionsTask.class);
remapJar.finalizedBy(deduplicateInclusions);
deduplicateInclusions.getInputs().files(remapJar.getOutputs().getFiles());
TaskContainer tasks = project.getTasks();
// mark standard output as non-deduplicated
tasks.named("remapJar", Jar.class).configure(remapJar -> remapJar.getArchiveClassifier().convention("duplicated"));

// based on loom remapJar setup
tasks.create("deduplicateInclusions", DeduplicateInclusionsTask.class, deduplicate -> {
Jar remapJar = tasks.named("remapJar", Jar.class).get();
deduplicate.dependsOn(remapJar);

deduplicate.getArchiveBaseName().convention(remapJar.getArchiveBaseName());
deduplicate.getArchiveAppendix().convention(remapJar.getArchiveAppendix());
deduplicate.getArchiveVersion().convention(remapJar.getArchiveVersion());
deduplicate.getArchiveExtension().convention(remapJar.getArchiveExtension());

deduplicate.getDuplicatedJar().convention(remapJar.getArchiveFile());
project.getArtifacts().add(JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME, deduplicate);
project.getArtifacts().add(JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME, deduplicate);
});

// make build use the deduplication
tasks.named(BasePlugin.ASSEMBLE_TASK_NAME).configure(
assemble -> assemble.dependsOn(tasks.named("deduplicateInclusions"))
);
}

public void setupResourceProcessing(Project project) {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit a660da0

Please sign in to comment.