import net.minecraftforge.artifactural.buildscript.JarTransformationTask import net.minecraftforge.artifactural.buildscript.SoftwareComponentFactoryGrabber import org.objectweb.asm.Label import org.objectweb.asm.Opcodes import org.objectweb.asm.tree.InsnNode import org.objectweb.asm.tree.MethodInsnNode plugins { id 'java-library' id 'maven-publish' id 'eclipse' id 'org.cadixdev.licenser' version '0.6.1' id 'net.minecraftforge.gradleutils' version '2.+' } group = 'net.minecraftforge' version = gradleutils.getTagOffsetVersion() println('Version: ' + version + ' Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch')) sourceSets { api shared gradlecomp } repositories { mavenCentral() maven { url = 'https://maven.minecraftforge.net' } } configurations { sharedImplementation.extendsFrom apiImplementation gradlecompImplementation.extendsFrom sharedImplementation implementation.extendsFrom sharedImplementation implementation.extendsFrom gradlecompImplementation } dependencies { sharedImplementation sourceSets.api.output gradlecompImplementation sourceSets.shared.output gradlecompImplementation gradleApi() gradlecompImplementation 'com.google.guava:guava:30.1-jre' gradlecompImplementation 'net.minecraftforge:unsafe:0.2.0' implementation sourceSets.api.output implementation sourceSets.shared.output implementation sourceSets.gradlecomp.output } tasks.withType(JavaCompile).configureEach { options.encoding = 'utf-8' options.deprecation = true } java { toolchain.languageVersion = JavaLanguageVersion.of(8) withSourcesJar() } tasks.register('transformJar', JarTransformationTask) { addTransformer('net/minecraftforge/artifactural/gradle/GradleRepositoryAdapter') { it.methods.find { it.name == '' && it.desc == '(Lnet/minecraftforge/artifactural/api/repository/Repository;Lorg/gradle/api/internal/artifacts/repositories/DefaultMavenLocalArtifactRepository;)V' }?.tap { it.instructions.find { it instanceof InsnNode && it.opcode == Opcodes.ACONST_NULL }?.tap(it.instructions.&remove) it.instructions.find { it instanceof MethodInsnNode && it.owner == 'org/gradle/api/internal/artifacts/repositories/AbstractArtifactRepository' && it.name == '' }?.tap { (it as MethodInsnNode).desc = '(Lorg/gradle/api/model/ObjectFactory;)V' } } } addTransformer('net/minecraftforge/artifactural/gradle/GradleRepositoryAdapter$1$1') { clazz -> // Gradle [6.1,7.6) { final method = clazz.visitMethod(Opcodes.ACC_PUBLIC, 'resolveArtifact', '(Lorg/gradle/internal/component/model/ComponentArtifactMetadata;Lorg/gradle/internal/component/model/ModuleSources;Lorg/gradle/internal/resolve/result/BuildableArtifactResolveResult;)V', null, new String[]{}) final l0 = new Label() method.visitLabel(l0) method.visitVarInsn(Opcodes.ALOAD, 0) method.visitFieldInsn(Opcodes.GETFIELD, 'net/minecraftforge/artifactural/gradle/GradleRepositoryAdapter$1$1', 'val$delegate', 'Lorg/gradle/api/internal/artifacts/ivyservice/ivyresolve/ModuleComponentRepositoryAccess;') method.visitVarInsn(Opcodes.ALOAD, 1) method.visitVarInsn(Opcodes.ALOAD, 2) method.visitVarInsn(Opcodes.ALOAD, 3) method.visitMethodInsn(Opcodes.INVOKEINTERFACE, 'org/gradle/api/internal/artifacts/ivyservice/ivyresolve/ModuleComponentRepositoryAccess', 'resolveArtifact', '(Lorg/gradle/internal/component/model/ComponentArtifactMetadata;Lorg/gradle/internal/component/model/ModuleSources;Lorg/gradle/internal/resolve/result/BuildableArtifactResolveResult;)V', true) final l1 = new Label() method.visitLabel(l1) method.visitInsn(Opcodes.RETURN) final l2 = new Label() method.visitLabel(l2) method.visitLocalVariable('this', 'Lnet/minecraftforge/artifactural/gradle/GradleRepositoryAdapter$1$1;', null, l0, l2, 0) method.visitLocalVariable('artifact', 'Lorg/gradle/internal/component/model/ComponentArtifactMetadata;', null, l0, l2, 1) method.visitLocalVariable('moduleSources', 'Lorg/gradle/internal/component/model/ModuleSources;', null, l0, l2, 2) method.visitLocalVariable('result', 'Lorg/gradle/internal/resolve/result/BuildableArtifactResolveResult;', null, l0, l2, 3) method.visitEnd() } // Gradle [6.0,7.6) { final method = clazz.visitMethod(Opcodes.ACC_PUBLIC, 'resolveArtifacts', '(Lorg/gradle/internal/component/model/ComponentResolveMetadata;Lorg/gradle/internal/component/model/ConfigurationMetadata;Lorg/gradle/internal/resolve/result/BuildableComponentArtifactsResolveResult;)V', null, new String[]{}) final l0 = new Label() method.visitLabel(l0) method.visitVarInsn(Opcodes.ALOAD, 0) method.visitFieldInsn(Opcodes.GETFIELD, 'net/minecraftforge/artifactural/gradle/GradleRepositoryAdapter$1$1', 'val$delegate', 'Lorg/gradle/api/internal/artifacts/ivyservice/ivyresolve/ModuleComponentRepositoryAccess;') method.visitVarInsn(Opcodes.ALOAD, 1) method.visitVarInsn(Opcodes.ALOAD, 2) method.visitVarInsn(Opcodes.ALOAD, 3) method.visitMethodInsn(Opcodes.INVOKEINTERFACE, 'org/gradle/api/internal/artifacts/ivyservice/ivyresolve/ModuleComponentRepositoryAccess', 'resolveArtifacts', '(Lorg/gradle/internal/component/model/ComponentResolveMetadata;Lorg/gradle/internal/component/model/ConfigurationMetadata;Lorg/gradle/internal/resolve/result/BuildableComponentArtifactsResolveResult;)V', true) final l1 = new Label() method.visitLabel(l1) method.visitInsn(Opcodes.RETURN) final l2 = new Label() method.visitLabel(l2) method.visitLocalVariable('this', 'Lnet/minecraftforge/artifactural/gradle/GradleRepositoryAdapter$1$1;', null, l0, l2, 0) method.visitLocalVariable('component', 'Lorg/gradle/internal/component/model/ComponentResolveMetadata;', null, l0, l2, 1) method.visitLocalVariable('variant', 'Lorg/gradle/internal/component/model/ConfigurationMetadata;', null, l0, l2, 2) method.visitLocalVariable('result', 'Lorg/gradle/internal/resolve/result/BuildableComponentArtifactsResolveResult;', null, l0, l2, 3) method.visitEnd() } // Gradle [3.1,6.0) U [7.5,7.6) { final method = clazz.visitMethod(Opcodes.ACC_PUBLIC, 'resolveArtifacts', '(Lorg/gradle/internal/component/model/ComponentResolveMetadata;Lorg/gradle/internal/resolve/result/BuildableComponentArtifactsResolveResult;)V', null, new String[]{}) final l0 = new Label() method.visitLabel(l0) method.visitVarInsn(Opcodes.ALOAD, 0) method.visitFieldInsn(Opcodes.GETFIELD, 'net/minecraftforge/artifactural/gradle/GradleRepositoryAdapter$1$1', 'val$delegate', 'Lorg/gradle/api/internal/artifacts/ivyservice/ivyresolve/ModuleComponentRepositoryAccess;') method.visitVarInsn(Opcodes.ALOAD, 1) method.visitVarInsn(Opcodes.ALOAD, 2) method.visitMethodInsn(Opcodes.INVOKEINTERFACE, 'org/gradle/api/internal/artifacts/ivyservice/ivyresolve/ModuleComponentRepositoryAccess', 'resolveArtifacts', '(Lorg/gradle/internal/component/model/ComponentResolveMetadata;Lorg/gradle/internal/resolve/result/BuildableComponentArtifactsResolveResult;)V', true) final l1 = new Label() method.visitLabel(l1) method.visitInsn(Opcodes.RETURN) final l2 = new Label() method.visitLabel(l2) method.visitLocalVariable('this', 'Lnet/minecraftforge/artifactural/gradle/GradleRepositoryAdapter$1$1;', null, l0, l2, 0) method.visitLocalVariable('component', 'Lorg/gradle/internal/component/model/ComponentResolveMetadata;', null, l0, l2, 1) method.visitLocalVariable('result', 'Lorg/gradle/internal/resolve/result/BuildableComponentArtifactsResolveResult;', null, l0, l2, 3) method.visitEnd() } } inputFile = tasks.named('jar').flatMap { it.archiveFile } outputFile = project.layout.buildDirectory.dir('libs').flatMap { dir -> tasks.named('jar').flatMap { it.archiveFileName }.map { String name -> dir.file(name.substring(0, name.length() - 4) + '-transformed.jar') } } } jar { from sourceSets.api.output from sourceSets.shared.output from sourceSets.gradlecomp.output finalizedBy 'transformJar' } sourcesJar { from sourceSets.api.allSource from sourceSets.shared.allSource from sourceSets.gradlecomp.allSource } license { header = file("$rootDir/LICENSE-header.txt") } configurations.runtimeElements.outgoing { it.artifacts.removeIf { (it.classifier == null || it.classifier.blank) && it.extension == 'jar' // Remove the jar artifact as we want to replace it with the transformed one } it.artifact(tasks.named('transformJar').flatMap { it.outputFile }) { classifier = null } } final transformed = project.objects.newInstance(SoftwareComponentFactoryGrabber).softwareComponentFactory.adhoc('transformed') project.components.add(transformed) transformed.addVariantsFromConfiguration(configurations.runtimeElements) { mapToMavenScope 'runtime' } publishing { publications.create("mavenJava", MavenPublication) { from components.transformed artifact sourcesJar pom { groupId = project.group version = project.version artifactId = project.archivesBaseName name = project.archivesBaseName packaging = 'jar' description = 'A Gradle artifact processing and management tool' url = 'https://github.com/MinecraftForge/Artifactural/' scm { url = 'https://github.com/MinecraftForge/Artifactural/' connection = 'scm:git:git://github.com/MinecraftForge/Artifactural.git' developerConnection = 'scm:git:git@github.com:MinecraftForge/Artifactural.git' } issueManagement { system = 'github' url = 'https://github.com/MinecraftForge/Artifactural/issues' } licenses { license { name = 'LGPL-2.1' url = 'https://www.gnu.org/licenses/lgpl-2.1.txt' distribution = 'repo' } } } } repositories { maven gradleutils.getPublishingForgeMaven() } } changelog { fromTag('3.0') }