More improvements/fixes to shared caches maven publications + test improvements.

dev/0.11
modmuss50 2021-11-25 14:49:17 +00:00 committed by GitHub
parent 9ddff5f31a
commit 7b28d61fab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 97 additions and 19 deletions

View File

@ -101,7 +101,7 @@ dependencies {
exclude module: 'groovy-all'
}
testImplementation 'io.javalin:javalin:3.13.11'
testImplementation 'net.fabricmc:fabric-installer:0.7.4'
testImplementation 'net.fabricmc:fabric-installer:0.9.0'
compileOnly 'org.jetbrains:annotations:22.0.0'
}

View File

@ -31,6 +31,7 @@ import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.UnknownTaskException;
import org.gradle.api.artifacts.ConfigurablePublishArtifact;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.PublishArtifact;
import org.gradle.api.artifacts.dsl.ArtifactHandler;
@ -64,24 +65,17 @@ public class RemapConfiguration {
if (extension.getSetupRemappedVariants().get()) {
ArtifactHandler artifacts = project.getArtifacts();
project.getTasks().named(DEFAULT_REMAP_JAR_TASK_NAME, task -> {
artifacts.add(JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME, task);
artifacts.add(JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME, task);
artifacts.add(JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME, task, artifactConfigurationAction(task, DEFAULT_REMAP_JAR_TASK_NAME, project));
artifacts.add(JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME, task, artifactConfigurationAction(task, DEFAULT_REMAP_JAR_TASK_NAME, project));
});
project.getTasks().named(DEFAULT_REMAP_SOURCES_JAR_TASK_NAME, RemapSourcesJarTask.class, task -> {
if (!project.getConfigurations().getNames().contains(JavaPlugin.SOURCES_ELEMENTS_CONFIGURATION_NAME)) {
// Sources jar may not have been created with withSourcesJar
project.getLogger().info("Not publishing sources jar as it was not found. Use java.withSourcesJar() to fix.");
return;
}
PublishArtifact artifact = artifacts.add(JavaPlugin.SOURCES_ELEMENTS_CONFIGURATION_NAME, task.getOutput(), configurablePublishArtifact -> {
Task remapJarTask = task;
if (extension.getShareRemapCaches().get()) {
remapJarTask = project.getRootProject().getTasks().getByName(DEFAULT_REMAP_ALL_JARS_TASK_NAME);
}
configurablePublishArtifact.builtBy(remapJarTask);
});
PublishArtifact artifact = artifacts.add(JavaPlugin.SOURCES_ELEMENTS_CONFIGURATION_NAME, task.getOutput(), artifactConfigurationAction(task, DEFAULT_REMAP_ALL_SOURCES_TASK_NAME, project));
// Remove the existing artifact that does not run remapSourcesJar.
// It doesn't seem to hurt, but I'm not sure if the file-level duplicates cause issues.
@ -209,4 +203,18 @@ public class RemapConfiguration {
// pass
}
}
private static Action<ConfigurablePublishArtifact> artifactConfigurationAction(Task standardTask, String sharedTaskName, Project project) {
LoomGradleExtension extension = LoomGradleExtension.get(project);
return artifact -> {
Task remapTask = standardTask;
if (extension.getShareRemapCaches().get()) {
remapTask = project.getRootProject().getTasks().getByName(sharedTaskName);
}
artifact.builtBy(remapTask);
};
}
}

View File

@ -28,7 +28,7 @@ import org.gradle.util.GradleVersion
class LoomTestConstants {
public final static String DEFAULT_GRADLE = GradleVersion.current().getVersion()
public final static String PRE_RELEASE_GRADLE = "7.4-20211110232442+0000"
public final static String PRE_RELEASE_GRADLE = "7.4-20211124232407+0000"
public final static String[] STANDARD_TEST_VERSIONS = [DEFAULT_GRADLE, PRE_RELEASE_GRADLE]
}

View File

@ -43,10 +43,10 @@ class FabricAPITest extends Specification implements GradleProjectTestTrait {
def "build and run (gradle #version)"() {
setup:
def gradle = gradleProject(
repo: "https://github.com/modmuss50/fabric.git",
commit: "e954edb6069e36139fd70428cfe4cddb5826c498",
repo: "https://github.com/FabricMC/fabric.git",
commit: "ce6198f63bbe0e17ba631420e9186fb72cc8b2af",
version: version,
// patch: "fabric_api"
patch: "fabric_api"
)
// Set the version to something constant
@ -62,8 +62,11 @@ class FabricAPITest extends Specification implements GradleProjectTestTrait {
then:
result.task(":build").outcome == SUCCESS
new File(gradle.mavenLocalDir, "net/fabricmc/fabric-api/fabric-biome-api-v1/3.2.2/fabric-biome-api-v1-3.2.2.jar").exists()
new File(gradle.mavenLocalDir, "net/fabricmc/fabric-api/fabric-biome-api-v1/3.2.2/fabric-biome-api-v1-3.2.2-sources.jar").exists()
serverResult.successful()
serverResult.output.contains("fabric@$API_VERSION")
serverResult.output.contains("- fabric $API_VERSION")
where:
version << STANDARD_TEST_VERSIONS
}

View File

@ -53,6 +53,7 @@ class MavenProjectTest extends Specification implements MockMavenServerTrait, Gr
then:
result.task(":publish").outcome == SUCCESS
gradle.hasOutputZipEntry("fabric-example-lib-${version}.jar", "net/fabricmc/example/ExampleLib.class")
gradle.hasOutputZipEntry("fabric-example-lib-${version}-sources.jar", "net/fabricmc/example/ExampleLib.java")
where:
version | gradleVersion

View File

@ -138,7 +138,7 @@ trait GradleProjectTestTrait {
// And override the CI check to ensure that everything is ran
System.setProperty("fabric.loom.test", "true")
System.setProperty("fabric.loom.ci", "false")
System.setProperty("maven.repo.local", new File(getGradleHomeDir(), "m2").absolutePath)
System.setProperty("maven.repo.local", mavenLocalDir.absolutePath)
def runner = this.runner
def args = []
@ -180,6 +180,10 @@ trait GradleProjectTestTrait {
return new File(getProjectDir(), "build/libs/$filename")
}
File getMavenLocalDir() {
return new File(gradleHomeDir, "m2")
}
void printOutputFiles() {
new File(getProjectDir(), "build/libs/").listFiles().each {
println(it.name)

View File

@ -29,7 +29,7 @@ import groovy.transform.Immutable
import java.util.concurrent.TimeUnit
class ServerRunner {
static final String LOADER_VERSION = "0.11.6"
static final String LOADER_VERSION = "0.12.5"
static final Map<String, String> FABRIC_API_URLS = [
"1.16.5": "https://github.com/FabricMC/fabric/releases/download/0.37.1%2B1.16/fabric-api-0.37.1+1.16.jar",
"1.17.1": "https://github.com/FabricMC/fabric/releases/download/0.37.1%2B1.17/fabric-api-0.37.1+1.17.jar"

View File

@ -0,0 +1,62 @@
diff --git a/build.gradle b/build.gradle
--- a/build.gradle (revision ce6198f63bbe0e17ba631420e9186fb72cc8b2af)
+++ b/build.gradle (date 1637848132986)
@@ -31,17 +31,7 @@
throw new NullPointerException("Could not find version for " + project.name)
}
- if (grgit == null) {
- return version + "+nogit"
- }
-
- def latestCommits = grgit.log(paths: [project.name], maxCommits: 1)
-
- if (latestCommits.isEmpty()) {
- return version + "+uncommited"
- }
-
- return version + "+" + latestCommits.get(0).id.substring(0, 8) + DigestUtils.sha256Hex(project.rootProject.minecraft_version).substring(0, 2)
+ return version
}
def getBranch() {
@@ -132,9 +122,8 @@
include "**/*.java"
}
- task sourcesJar(type: Jar, dependsOn: classes) {
- archiveClassifier = "sources"
- from sourceSets.main.allSource
+ java {
+ withSourcesJar()
}
checkstyle {
@@ -229,12 +218,16 @@
publications {
mavenJava(MavenPublication) {
from components.java
+
+ artifact javadocJar
}
}
setupRepositories(repositories)
}
+ loom.disableDeprecatedPomGeneration(publishing.publications.mavenJava)
+
javadoc.enabled = false
afterEvaluate {
@@ -242,10 +235,6 @@
genSourcesWithFernFlower.enabled = false
genSourcesWithCfr.enabled = false
unpickJar.enabled = false
-
- // Work around a loom bug causing empty jars to be pushed to maven local.
- publishMavenJavaPublicationToMavenLocal.dependsOn rootProject.tasks.getByName("remapAllJars")
- publishMavenJavaPublicationToMavenLocal.dependsOn rootProject.tasks.getByName("remapAllSources")
}
}