Update to Gradle 7 (#380)
* Gradle 7 part 1 * Fix actions? * Update actions * Fix tests not running * Fix some broken tests * Update kotlin to try and fix JDK 16 support * Disable KotlinTest on j16 * exclude kotlin test from actions...
This commit is contained in:
		
							parent
							
								
									98731532d5
								
							
						
					
					
						commit
						c8df12cf0f
					
				
					 18 changed files with 48 additions and 111 deletions
				
			
		
							
								
								
									
										2
									
								
								.github/workflows/publish.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/publish.yml
									
									
									
									
										vendored
									
									
								
							|  | @ -8,7 +8,7 @@ jobs: | ||||||
|   build: |   build: | ||||||
|     runs-on: ubuntu-20.04 |     runs-on: ubuntu-20.04 | ||||||
|     container: |     container: | ||||||
|       image: openjdk:8-jdk |       image: openjdk:16-jdk | ||||||
|       options: --user root |       options: --user root | ||||||
|     steps: |     steps: | ||||||
|       - uses: actions/checkout@v1 |       - uses: actions/checkout@v1 | ||||||
|  |  | ||||||
							
								
								
									
										27
									
								
								.github/workflows/test-push.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										27
									
								
								.github/workflows/test-push.yml
									
									
									
									
										vendored
									
									
								
							|  | @ -5,20 +5,12 @@ jobs: | ||||||
|     strategy: |     strategy: | ||||||
|       fail-fast: false |       fail-fast: false | ||||||
|       matrix: |       matrix: | ||||||
|         gradle: [4.9, 4.10.2, 6.8.3] |         gradle: [7.0-rc-2] | ||||||
|         java: [jdk8, jdk11, jdk15] |         java: [jdk8, jdk11, jdk16] | ||||||
|         exclude: # Dont run older gradle versions on newer java |         jvm: [hotspot] | ||||||
|           - java: jdk15 |  | ||||||
|             gradle: 4.9 |  | ||||||
|           - java: jdk15 |  | ||||||
|             gradle: 4.10.2 |  | ||||||
|           - java: jdk11 |  | ||||||
|             gradle: 4.9 |  | ||||||
|           - java: jdk11 |  | ||||||
|             gradle: 4.10.2 |  | ||||||
|     runs-on: ubuntu-20.04 |     runs-on: ubuntu-20.04 | ||||||
|     container: |     container: | ||||||
|       image: gradle:${{ matrix.gradle }}-${{ matrix.java }} |       image: ghcr.io/modmuss50/gradle:${{ matrix.gradle }}-${{ matrix.java }}-hotspot | ||||||
|       options: --user root |       options: --user root | ||||||
|     steps: |     steps: | ||||||
|       - uses: actions/checkout@v2 |       - uses: actions/checkout@v2 | ||||||
|  | @ -32,7 +24,7 @@ jobs: | ||||||
| 
 | 
 | ||||||
|     runs-on: ubuntu-20.04 |     runs-on: ubuntu-20.04 | ||||||
|     container: |     container: | ||||||
|       image: gradle:6.8.3-jdk15 |       image: ghcr.io/modmuss50/gradle:7.0-rc-2-jdk16-hotspot | ||||||
|       options: --user root |       options: --user root | ||||||
| 
 | 
 | ||||||
|     steps: |     steps: | ||||||
|  | @ -51,12 +43,15 @@ jobs: | ||||||
|     strategy: |     strategy: | ||||||
|       fail-fast: false |       fail-fast: false | ||||||
|       matrix: |       matrix: | ||||||
|         java: [jdk8, jdk11, jdk15] |         java: [jdk8, jdk11, jdk16] | ||||||
|         test: ${{ fromJson(needs.prepare_test_matrix.outputs.matrix) }} |         test: ${{ fromJson(needs.prepare_test_matrix.outputs.matrix) }} | ||||||
|  |         exclude: | ||||||
|  |           - java: jdk16 | ||||||
|  |             test: net.fabricmc.loom.test.intergration.KotlinTest | ||||||
| 
 | 
 | ||||||
|     runs-on: ubuntu-20.04 |     runs-on: ubuntu-20.04 | ||||||
|     container: |     container: | ||||||
|       image: gradle:6.8.3-${{ matrix.java }} |       image: ghcr.io/modmuss50/gradle:7.0-rc-2-${{ matrix.java }}-hotspot | ||||||
|       options: --user root |       options: --user root | ||||||
| 
 | 
 | ||||||
|     steps: |     steps: | ||||||
|  | @ -78,7 +73,7 @@ jobs: | ||||||
|     strategy: |     strategy: | ||||||
|       fail-fast: false |       fail-fast: false | ||||||
|       matrix: |       matrix: | ||||||
|         java: [ 1.8, 11, 15 ] |         java: [ 1.8, 11, 16 ] | ||||||
|         os: [ windows-2019, ubuntu-20.04, macos-10.15 ] |         os: [ windows-2019, ubuntu-20.04, macos-10.15 ] | ||||||
| 
 | 
 | ||||||
|     runs-on: ${{ matrix.os }} |     runs-on: ${{ matrix.os }} | ||||||
|  |  | ||||||
							
								
								
									
										23
									
								
								build.gradle
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								build.gradle
									
									
									
									
									
								
							|  | @ -14,6 +14,15 @@ plugins { | ||||||
| sourceCompatibility = 1.8 | sourceCompatibility = 1.8 | ||||||
| targetCompatibility = 1.8 | targetCompatibility = 1.8 | ||||||
| 
 | 
 | ||||||
|  | tasks.withType(JavaCompile).configureEach { | ||||||
|  | 	it.options.encoding = "UTF-8" | ||||||
|  | 
 | ||||||
|  | 	if (JavaVersion.current().isJava9Compatible()) { | ||||||
|  | 		it.options.release = 8 | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| group = 'net.fabricmc' | group = 'net.fabricmc' | ||||||
| archivesBaseName = project.name | archivesBaseName = project.name | ||||||
| def baseVersion = '0.7' | def baseVersion = '0.7' | ||||||
|  | @ -36,9 +45,6 @@ repositories { | ||||||
| dependencies { | dependencies { | ||||||
| 	implementation gradleApi() | 	implementation gradleApi() | ||||||
| 
 | 
 | ||||||
| 	// Compile against groovy 3 to aid with gradle 7 support. Remove when updating to gradle 7 |  | ||||||
| 	compileOnly 'org.codehaus.groovy:groovy-all:3.0.7' |  | ||||||
| 
 |  | ||||||
| 	// libraries | 	// libraries | ||||||
| 	implementation ('commons-io:commons-io:2.8.0') | 	implementation ('commons-io:commons-io:2.8.0') | ||||||
| 	implementation ('org.zeroturnaround:zt-zip:1.14') | 	implementation ('org.zeroturnaround:zt-zip:1.14') | ||||||
|  | @ -74,11 +80,11 @@ dependencies { | ||||||
| 	implementation ('org.cadixdev:mercury:0.1.0-rc1') | 	implementation ('org.cadixdev:mercury:0.1.0-rc1') | ||||||
| 
 | 
 | ||||||
| 	// Kapt integration | 	// Kapt integration | ||||||
| 	compileOnly('org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.21') | 	compileOnly('org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.32') | ||||||
| 
 | 
 | ||||||
| 	// Testing | 	// Testing | ||||||
| 	testImplementation(gradleTestKit()) | 	testImplementation(gradleTestKit()) | ||||||
| 	testImplementation('org.spockframework:spock-core:1.3-groovy-2.4') { | 	testImplementation('org.spockframework:spock-core:2.0-M5-groovy-3.0') { | ||||||
| 		exclude module: 'groovy-all' | 		exclude module: 'groovy-all' | ||||||
| 	} | 	} | ||||||
| 	testImplementation 'io.javalin:javalin:3.13.4' | 	testImplementation 'io.javalin:javalin:3.13.4' | ||||||
|  | @ -93,12 +99,12 @@ jar { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| task sourcesJar(type: Jar, dependsOn: classes) { | task sourcesJar(type: Jar, dependsOn: classes) { | ||||||
| 	classifier = 'sources' | 	archiveClassifier = 'sources' | ||||||
| 	from sourceSets.main.allSource | 	from sourceSets.main.allSource | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| task javadocJar(type: Jar, dependsOn: javadoc) { | task javadocJar(type: Jar, dependsOn: javadoc) { | ||||||
| 	classifier = 'javadoc' | 	archiveClassifier = 'javadoc' | ||||||
| 	from javadoc.destinationDir | 	from javadoc.destinationDir | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -112,7 +118,7 @@ license { | ||||||
| 
 | 
 | ||||||
| checkstyle { | checkstyle { | ||||||
| 	configFile = file('checkstyle.xml') | 	configFile = file('checkstyle.xml') | ||||||
| 	toolVersion = '8.39' | 	toolVersion = '8.41.1' | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| codenarc { | codenarc { | ||||||
|  | @ -145,6 +151,7 @@ jacocoTestReport { | ||||||
| 
 | 
 | ||||||
| test { | test { | ||||||
| 	maxHeapSize = "4096m" | 	maxHeapSize = "4096m" | ||||||
|  | 	useJUnitPlatform() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| import org.w3c.dom.Document | import org.w3c.dom.Document | ||||||
|  |  | ||||||
							
								
								
									
										
											BIN
										
									
								
								gradle/wrapper/gradle-wrapper.jar
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								gradle/wrapper/gradle-wrapper.jar
									
									
									
									
										vendored
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										3
									
								
								gradle/wrapper/gradle-wrapper.properties
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								gradle/wrapper/gradle-wrapper.properties
									
									
									
									
										vendored
									
									
								
							|  | @ -1,6 +1,5 @@ | ||||||
| #Mon Jun 24 11:09:08 BST 2019 |  | ||||||
| distributionBase=GRADLE_USER_HOME | distributionBase=GRADLE_USER_HOME | ||||||
| distributionPath=wrapper/dists | distributionPath=wrapper/dists | ||||||
|  | distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-rc-2-bin.zip | ||||||
| zipStoreBase=GRADLE_USER_HOME | zipStoreBase=GRADLE_USER_HOME | ||||||
| zipStorePath=wrapper/dists | zipStorePath=wrapper/dists | ||||||
| distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip |  | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								gradlew
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								gradlew
									
									
									
									
										vendored
									
									
								
							|  | @ -28,7 +28,7 @@ APP_NAME="Gradle" | ||||||
| APP_BASE_NAME=`basename "$0"` | APP_BASE_NAME=`basename "$0"` | ||||||
| 
 | 
 | ||||||
| # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. | ||||||
| DEFAULT_JVM_OPTS='"-Xmx64m"' | DEFAULT_JVM_OPTS="" | ||||||
| 
 | 
 | ||||||
| # Use the maximum available, or set MAX_FD != -1 to use that value. | # Use the maximum available, or set MAX_FD != -1 to use that value. | ||||||
| MAX_FD="maximum" | MAX_FD="maximum" | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								gradlew.bat
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								gradlew.bat
									
									
									
									
										vendored
									
									
								
							|  | @ -14,7 +14,7 @@ set APP_BASE_NAME=%~n0 | ||||||
| set APP_HOME=%DIRNAME% | set APP_HOME=%DIRNAME% | ||||||
| 
 | 
 | ||||||
| @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. | ||||||
| set DEFAULT_JVM_OPTS="-Xmx64m" | set DEFAULT_JVM_OPTS= | ||||||
| 
 | 
 | ||||||
| @rem Find java.exe | @rem Find java.exe | ||||||
| if defined JAVA_HOME goto findJavaFromJavaHome | if defined JAVA_HOME goto findJavaFromJavaHome | ||||||
|  |  | ||||||
|  | @ -27,9 +27,6 @@ package net.fabricmc.loom.configuration; | ||||||
| import org.gradle.api.artifacts.ConfigurationContainer; | import org.gradle.api.artifacts.ConfigurationContainer; | ||||||
| import org.gradle.api.plugins.JavaPlugin; | import org.gradle.api.plugins.JavaPlugin; | ||||||
| 
 | 
 | ||||||
| import net.fabricmc.loom.util.Constants; |  | ||||||
| import net.fabricmc.loom.util.gradle.GradleSupport; |  | ||||||
| 
 |  | ||||||
| public class RemappedConfigurationEntry { | public class RemappedConfigurationEntry { | ||||||
| 	private final String sourceConfiguration; | 	private final String sourceConfiguration; | ||||||
| 	private final String targetConfiguration; | 	private final String targetConfiguration; | ||||||
|  | @ -65,7 +62,7 @@ public class RemappedConfigurationEntry { | ||||||
| 
 | 
 | ||||||
| 	public String getTargetConfiguration(ConfigurationContainer container) { | 	public String getTargetConfiguration(ConfigurationContainer container) { | ||||||
| 		if (container.findByName(targetConfiguration) == null) { | 		if (container.findByName(targetConfiguration) == null) { | ||||||
| 			return GradleSupport.IS_GRADLE_7_OR_NEWER ? JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME : Constants.Configurations.COMPILE; | 			return JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		return targetConfiguration; | 		return targetConfiguration; | ||||||
|  |  | ||||||
|  | @ -61,7 +61,6 @@ import net.fabricmc.loom.configuration.accesswidener.AccessWidenerJarProcessor; | ||||||
| import net.fabricmc.loom.configuration.providers.mappings.MappingsProvider; | import net.fabricmc.loom.configuration.providers.mappings.MappingsProvider; | ||||||
| import net.fabricmc.loom.util.Constants; | import net.fabricmc.loom.util.Constants; | ||||||
| import net.fabricmc.loom.util.TinyRemapperMappingsHelper; | import net.fabricmc.loom.util.TinyRemapperMappingsHelper; | ||||||
| import net.fabricmc.loom.util.gradle.GradleSupport; |  | ||||||
| import net.fabricmc.loom.util.ZipReprocessorUtil; | import net.fabricmc.loom.util.ZipReprocessorUtil; | ||||||
| import net.fabricmc.stitch.util.Pair; | import net.fabricmc.stitch.util.Pair; | ||||||
| import net.fabricmc.tinyremapper.TinyRemapper; | import net.fabricmc.tinyremapper.TinyRemapper; | ||||||
|  | @ -79,7 +78,7 @@ public class RemapJarTask extends Jar { | ||||||
| 
 | 
 | ||||||
| 	public RemapJarTask() { | 	public RemapJarTask() { | ||||||
| 		super(); | 		super(); | ||||||
| 		input = GradleSupport.getfileProperty(getProject()); | 		input = getProject().getObjects().fileProperty(); | ||||||
| 		addNestedDependencies = getProject().getObjects().property(Boolean.class); | 		addNestedDependencies = getProject().getObjects().property(Boolean.class); | ||||||
| 		addDefaultNestedDependencies = getProject().getObjects().property(Boolean.class); | 		addDefaultNestedDependencies = getProject().getObjects().property(Boolean.class); | ||||||
| 		remapAccessWidener = getProject().getObjects().property(Boolean.class); | 		remapAccessWidener = getProject().getObjects().property(Boolean.class); | ||||||
|  |  | ||||||
|  | @ -31,7 +31,6 @@ import org.gradle.api.plugins.JavaPlugin; | ||||||
| import org.objectweb.asm.Opcodes; | import org.objectweb.asm.Opcodes; | ||||||
| 
 | 
 | ||||||
| import net.fabricmc.loom.configuration.RemappedConfigurationEntry; | import net.fabricmc.loom.configuration.RemappedConfigurationEntry; | ||||||
| import net.fabricmc.loom.util.gradle.GradleSupport; |  | ||||||
| 
 | 
 | ||||||
| public class Constants { | public class Constants { | ||||||
| 	public static final String LIBRARIES_BASE = "https://libraries.minecraft.net/"; | 	public static final String LIBRARIES_BASE = "https://libraries.minecraft.net/"; | ||||||
|  | @ -42,23 +41,13 @@ public class Constants { | ||||||
| 
 | 
 | ||||||
| 	public static final int ASM_VERSION = Opcodes.ASM9; | 	public static final int ASM_VERSION = Opcodes.ASM9; | ||||||
| 
 | 
 | ||||||
| 	private static final List<RemappedConfigurationEntry> LEGACY_MOD_COMPILE_ENTRIES = ImmutableList.of( | 	public static final List<RemappedConfigurationEntry> MOD_COMPILE_ENTRIES = ImmutableList.of( | ||||||
| 			new RemappedConfigurationEntry("modCompile", Configurations.COMPILE, true, "compile"), |  | ||||||
| 			new RemappedConfigurationEntry("modApi", JavaPlugin.API_CONFIGURATION_NAME, true, "compile"), | 			new RemappedConfigurationEntry("modApi", JavaPlugin.API_CONFIGURATION_NAME, true, "compile"), | ||||||
| 			new RemappedConfigurationEntry("modImplementation", JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, true, "runtime"), | 			new RemappedConfigurationEntry("modImplementation", JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, true, "runtime"), | ||||||
| 			new RemappedConfigurationEntry("modRuntime", JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME, false, ""), | 			new RemappedConfigurationEntry("modRuntime", JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME, false, ""), | ||||||
| 			new RemappedConfigurationEntry("modCompileOnly", JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME, true, "") | 			new RemappedConfigurationEntry("modCompileOnly", JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME, true, "") | ||||||
| 	); | 	); | ||||||
| 
 | 
 | ||||||
| 	private static final List<RemappedConfigurationEntry> MODERN_MOD_COMPILE_ENTRIES = ImmutableList.of( |  | ||||||
| 			new RemappedConfigurationEntry("modApi", JavaPlugin.API_CONFIGURATION_NAME, true, "compile"), |  | ||||||
| 			new RemappedConfigurationEntry("modImplementation", JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, true, "runtime"), |  | ||||||
| 			new RemappedConfigurationEntry("modRuntime", JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME, false, ""), |  | ||||||
| 			new RemappedConfigurationEntry("modCompileOnly", JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME, true, "") |  | ||||||
| 	); |  | ||||||
| 
 |  | ||||||
| 	public static final List<RemappedConfigurationEntry> MOD_COMPILE_ENTRIES = GradleSupport.IS_GRADLE_7_OR_NEWER ? MODERN_MOD_COMPILE_ENTRIES : LEGACY_MOD_COMPILE_ENTRIES; |  | ||||||
| 
 |  | ||||||
| 	private Constants() { | 	private Constants() { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -77,8 +66,6 @@ public class Constants { | ||||||
| 		public static final String MAPPINGS_FINAL = "mappingsFinal"; | 		public static final String MAPPINGS_FINAL = "mappingsFinal"; | ||||||
| 		public static final String LOADER_DEPENDENCIES = "loaderLibraries"; | 		public static final String LOADER_DEPENDENCIES = "loaderLibraries"; | ||||||
| 		public static final String LOOM_DEVELOPMENT_DEPENDENCIES = "loomDevelopmentDependencies"; | 		public static final String LOOM_DEVELOPMENT_DEPENDENCIES = "loomDevelopmentDependencies"; | ||||||
| 		@Deprecated // Not to be used in gradle 7+ |  | ||||||
| 		public static final String COMPILE = "compile"; |  | ||||||
| 		public static final String MAPPING_CONSTANTS = "mappingsConstants"; | 		public static final String MAPPING_CONSTANTS = "mappingsConstants"; | ||||||
| 		public static final String UNPICK_CLASSPATH = "unpick"; | 		public static final String UNPICK_CLASSPATH = "unpick"; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -31,8 +31,6 @@ import java.util.stream.Stream; | ||||||
| import groovy.util.Node; | import groovy.util.Node; | ||||||
| import groovy.xml.QName; | import groovy.xml.QName; | ||||||
| 
 | 
 | ||||||
| import net.fabricmc.loom.util.gradle.GradleSupport; |  | ||||||
| 
 |  | ||||||
| public final class GroovyXmlUtil { | public final class GroovyXmlUtil { | ||||||
| 	private GroovyXmlUtil() { } | 	private GroovyXmlUtil() { } | ||||||
| 
 | 
 | ||||||
|  | @ -66,18 +64,13 @@ public final class GroovyXmlUtil { | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		// New groovy 3 (gradle 7) class | 		// New groovy 3 (gradle 7) class | ||||||
| 		if (GradleSupport.IS_GRADLE_7_OR_NEWER && nodeName.getClass().getName().equals("groovy.namespace.QName")) { | 		if (nodeName instanceof groovy.namespace.QName) { | ||||||
| 			return isSameNameGroovy3(nodeName, givenName); | 			return ((groovy.namespace.QName) nodeName).matches(givenName); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		throw new UnsupportedOperationException("Cannot determine if " + nodeName.getClass() + " is the same as a String"); | 		throw new UnsupportedOperationException("Cannot determine if " + nodeName.getClass() + " is the same as a String"); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// TODO Move out of its own method when requiring gradle 7 |  | ||||||
| 	private static boolean isSameNameGroovy3(Object nodeName, String givenName) { |  | ||||||
| 		return ((groovy.namespace.QName) nodeName).matches(givenName); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	public static Stream<Node> childrenNodesStream(Node node) { | 	public static Stream<Node> childrenNodesStream(Node node) { | ||||||
| 		//noinspection unchecked | 		//noinspection unchecked | ||||||
| 		return (Stream<Node>) (Stream) (((List<Object>) node.children()).stream().filter((i) -> i instanceof Node)); | 		return (Stream<Node>) (Stream) (((List<Object>) node.children()).stream().filter((i) -> i instanceof Node)); | ||||||
|  |  | ||||||
|  | @ -24,45 +24,12 @@ | ||||||
| 
 | 
 | ||||||
| package net.fabricmc.loom.util.gradle; | package net.fabricmc.loom.util.gradle; | ||||||
| 
 | 
 | ||||||
| import java.lang.reflect.Method; |  | ||||||
| 
 |  | ||||||
| import org.gradle.api.Project; |  | ||||||
| import org.gradle.api.file.RegularFileProperty; |  | ||||||
| import org.gradle.util.GradleVersion; | import org.gradle.util.GradleVersion; | ||||||
| 
 | 
 | ||||||
| // This is used to bridge the gap over large gradle api changes. | // This is used to bridge the gap over large gradle api changes. | ||||||
| public class GradleSupport { | public class GradleSupport { | ||||||
| 	public static final boolean IS_GRADLE_7_OR_NEWER = isIsGradle7OrNewer(); | 	public static final boolean IS_GRADLE_7_OR_NEWER = isIsGradle7OrNewer(); | ||||||
| 
 | 
 | ||||||
| 	public static RegularFileProperty getfileProperty(Project project) { |  | ||||||
| 		try { |  | ||||||
| 			// First try the new method, if that fails fall back. |  | ||||||
| 			return getfilePropertyModern(project); |  | ||||||
| 		} catch (Exception e) { |  | ||||||
| 			// Nope |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		try { |  | ||||||
| 			return getfilePropertyLegacy(project); |  | ||||||
| 		} catch (Exception e) { |  | ||||||
| 			throw new RuntimeException("Failed to find file property", e); |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	private static RegularFileProperty getfilePropertyModern(Project project) throws Exception { |  | ||||||
| 		return getfilePropertyLegacyFromObject(project.getObjects()); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	private static RegularFileProperty getfilePropertyLegacy(Project project) throws Exception { |  | ||||||
| 		return getfilePropertyLegacyFromObject(project.getLayout()); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	private static RegularFileProperty getfilePropertyLegacyFromObject(Object object) throws Exception { |  | ||||||
| 		Method method = object.getClass().getDeclaredMethod("fileProperty"); |  | ||||||
| 		method.setAccessible(true); |  | ||||||
| 		return (RegularFileProperty) method.invoke(object); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	public static boolean isIsGradle7OrNewer() { | 	public static boolean isIsGradle7OrNewer() { | ||||||
| 		String version = GradleVersion.current().getVersion(); | 		String version = GradleVersion.current().getVersion(); | ||||||
| 		return Integer.parseInt(version.substring(0, version.indexOf("."))) >= 7; | 		return Integer.parseInt(version.substring(0, version.indexOf("."))) >= 7; | ||||||
|  |  | ||||||
|  | @ -47,7 +47,6 @@ class DecompileTest extends Specification implements ProjectTestTrait { | ||||||
| 		where: | 		where: | ||||||
| 			decompiler 		| task								| gradle | 			decompiler 		| task								| gradle | ||||||
| 			'fernflower'	| "genSources"						| DEFAULT_GRADLE | 			'fernflower'	| "genSources"						| DEFAULT_GRADLE | ||||||
| 			'fernflower'	| "genSources"						| LEGACY_GRADLE |  | ||||||
| 			'fernflower'	| "genSources"						| PRE_RELEASE_GRADLE | 			'fernflower'	| "genSources"						| PRE_RELEASE_GRADLE | ||||||
| 			'cfr' 			| "genSourcesWithExperimentalCfr"	| DEFAULT_GRADLE | 			'cfr' 			| "genSourcesWithExperimentalCfr"	| DEFAULT_GRADLE | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -25,11 +25,13 @@ | ||||||
| package net.fabricmc.loom.test.intergration | package net.fabricmc.loom.test.intergration | ||||||
| 
 | 
 | ||||||
| import net.fabricmc.loom.test.util.ProjectTestTrait | import net.fabricmc.loom.test.util.ProjectTestTrait | ||||||
|  | import spock.lang.IgnoreIf | ||||||
| import spock.lang.Specification | import spock.lang.Specification | ||||||
| import spock.lang.Unroll | import spock.lang.Unroll | ||||||
| 
 | 
 | ||||||
| import static org.gradle.testkit.runner.TaskOutcome.SUCCESS | import static org.gradle.testkit.runner.TaskOutcome.SUCCESS | ||||||
| 
 | 
 | ||||||
|  | @IgnoreIf({ jvm.java16Compatible }) // Fails on J16 > due to https://youtrack.jetbrains.com/issue/KT-45566 | ||||||
| class KotlinTest extends Specification implements ProjectTestTrait { | class KotlinTest extends Specification implements ProjectTestTrait { | ||||||
| 	@Override | 	@Override | ||||||
| 	String name() { | 	String name() { | ||||||
|  |  | ||||||
|  | @ -40,7 +40,7 @@ class LegacyProjectTest extends Specification implements ProjectTestTrait { | ||||||
| 	@Unroll | 	@Unroll | ||||||
| 	def "build"() { | 	def "build"() { | ||||||
| 		when: | 		when: | ||||||
| 			def result = create("build", LEGACY_GRADLE) | 			def result = create("build", DEFAULT_GRADLE) | ||||||
| 		then: | 		then: | ||||||
| 			result.task(":build").outcome == SUCCESS | 			result.task(":build").outcome == SUCCESS | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -49,8 +49,8 @@ class ReproducibleBuildTest extends Specification implements ProjectTestTrait { | ||||||
| 			getOutputHash("fabric-example-mod-1.0.0-sources.jar") in sourceHash // Done for different line endings. | 			getOutputHash("fabric-example-mod-1.0.0-sources.jar") in sourceHash // Done for different line endings. | ||||||
| 		where: | 		where: | ||||||
| 			gradle              | modHash                               | sourceHash | 			gradle              | modHash                               | sourceHash | ||||||
| 			'6.8.3'     | "6132ffb4117adb7e258f663110552952"    | ["be31766e6cafbe4ae3bca9e35ba63169", "7348b0bd87d36d7ec6f3bca9c2b66062"] | 			DEFAULT_GRADLE      | "6132ffb4117adb7e258f663110552952"    | ["be31766e6cafbe4ae3bca9e35ba63169", "7348b0bd87d36d7ec6f3bca9c2b66062"] | ||||||
| 			'7.0-rc-1'  | "6132ffb4117adb7e258f663110552952"    | ["be31766e6cafbe4ae3bca9e35ba63169", "7348b0bd87d36d7ec6f3bca9c2b66062"] | 			PRE_RELEASE_GRADLE  | "6132ffb4117adb7e258f663110552952"    | ["be31766e6cafbe4ae3bca9e35ba63169", "7348b0bd87d36d7ec6f3bca9c2b66062"] | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	String getOutputHash(String name) { | 	String getOutputHash(String name) { | ||||||
|  |  | ||||||
|  | @ -28,8 +28,7 @@ import org.gradle.testkit.runner.BuildResult | ||||||
| import org.gradle.testkit.runner.GradleRunner | import org.gradle.testkit.runner.GradleRunner | ||||||
| 
 | 
 | ||||||
| trait ProjectTestTrait { | trait ProjectTestTrait { | ||||||
| 	final static String LEGACY_GRADLE = "4.9" | 	final static String DEFAULT_GRADLE = "7.0-rc-2" | ||||||
| 	final static String DEFAULT_GRADLE = "6.8.3" |  | ||||||
| 	final static String PRE_RELEASE_GRADLE = "7.0-rc-2" | 	final static String PRE_RELEASE_GRADLE = "7.0-rc-2" | ||||||
| 
 | 
 | ||||||
| 	static File gradleHome = File.createTempDir() | 	static File gradleHome = File.createTempDir() | ||||||
|  | @ -95,10 +94,6 @@ trait ProjectTestTrait { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	String warningMode(String gradleVersion) { | 	String warningMode(String gradleVersion) { | ||||||
| 		if (gradleVersion == LEGACY_GRADLE) { |  | ||||||
| 			return "all" |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		'fail' | 		'fail' | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -19,23 +19,20 @@ dependencies { | ||||||
| processResources { | processResources { | ||||||
| 	inputs.property "version", project.version | 	inputs.property "version", project.version | ||||||
| 
 | 
 | ||||||
| 	from(sourceSets.main.resources.srcDirs) { | 	filesMatching("fabric.mod.json") { | ||||||
| 		include "fabric.mod.json" |  | ||||||
| 		expand "version": project.version | 		expand "version": project.version | ||||||
| 	} | 	} | ||||||
| 
 |  | ||||||
| 	from(sourceSets.main.resources.srcDirs) { |  | ||||||
| 		exclude "fabric.mod.json" |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| tasks.withType(JavaCompile) { | tasks.withType(JavaCompile) { | ||||||
| 	options.encoding = "UTF-8" | 	options.encoding = "UTF-8" | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| task sourcesJar(type: Jar, dependsOn: classes) { | java { | ||||||
| 	classifier = "sources" | 	// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task | ||||||
| 	from sourceSets.main.allSource | 	// if it is present. | ||||||
|  | 	// If you remove this line, sources will not be generated. | ||||||
|  | 	withSourcesJar() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| jar { | jar { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue