// Apply plugin apply plugin: 'java' apply plugin: 'checkstyle' apply plugin: 'maven-publish' apply plugin: 'eclipse' apply plugin: 'idea' // Default tasks defaultTasks 'check', 'build' // Basic project information group = 'org.stianloader' version = buildVersion + "-" + upstreamMixinVersion + "-1" base { archivesName = 'sponge-mixin' } // Extended project information ext.projectName = 'Mixin' ext.inceptionYear = '2014' ext.packaging = 'jar' ext.asmVersion = project.hasProperty("asmVersion") ? asmVersion : '9.8' java { toolchain { languageVersion = JavaLanguageVersion.of(8) } toolchain { languageVersion = JavaLanguageVersion.of(11) } } repositories { mavenCentral() } sourceSets { java9 { java { compileClasspath += main.output java.setSrcDirs(new java.util.ArrayList()) java.srcDir(getProjectDir().toPath().resolve('src/main/java9')) } ext.languageVersion = 9 } } configurations { java9Implementation.extendsFrom(implementation) java9CompileOnly.extendsFrom(compileOnly) } // Project dependencies dependencies { implementation 'com.google.guava:guava:31.1-jre' implementation 'com.google.code.gson:gson:2.8.9' implementation "org.ow2.asm:asm-tree:$asmVersion" implementation "org.ow2.asm:asm-commons:$asmVersion" implementation "org.ow2.asm:asm-util:$asmVersion" java9CompileOnly 'org.apache.logging.log4j:log4j-core:2.11.2' } javadoc { exclude '**/throwables' options.encoding = 'UTF-8' exclude { it.relativePath.file && it.relativePath.pathString =~ 'tools' && !(it.name =~ /SuppressedBy|package-info/) } options { docTitle 'Welcome to the Mixin Javadoc' overview 'docs/javadoc/overview.html' addBooleanOption '-allow-script-in-comments', true } doLast { copy { from 'docs/javadoc/resources' into outputDirectory } } } eclipse { classpath { containers 'org.eclipse.buildship.core.gradleclasspathcontainer' file.whenMerged { entries.each { if (it.kind == 'con' || it.kind == 'lib') { it.entryAttributes['module'] = 'true' } } } } } // License header formatting task validateHeaders(type: SourceTask) { TextResource header = resources.text.fromFile("HEADER.txt") source = sourceSets.collect { it.allJava } doLast { def headerStr = header.asString() def javaSources = getSource().matching(pattern -> pattern.include("**/*.java")).files def failedFiles = [] for (def source : javaSources) { if (!source.text.startsWith(headerStr)) { failedFiles.add(source.name) logger.warn("File {} does not have the correct license header", source.path) } } if (!failedFiles.isEmpty()) { throw new RuntimeException("License header validation failed for the following files:\n" + failedFiles.join("\n")) } } } tasks.check.dependsOn(validateHeaders) checkstyle { configProperties = [ "name" : project.name, "organization": project.organization, "url" : project.url, "year" : project.inceptionYear ] configFile = file("checkstyle.xml") toolVersion = '10.17.0' } // Source compiler configuration tasks.withType(JavaCompile) { options.compilerArgs += ['-Xlint:all', '-Xlint:-path', '-proc:none'] options.deprecation = true options.encoding = 'utf8' } compileJava { javaCompiler = javaToolchains.compilerFor { languageVersion = JavaLanguageVersion.of(8) } sourceCompatibility = '1.8' targetCompatibility = '1.8' } compileJava9Java { javaCompiler = javaToolchains.compilerFor { languageVersion = JavaLanguageVersion.of(11) } dependsOn compileJava sourceCompatibility = '9' targetCompatibility = '9' modularity.inferModulePath.set(true) options.javaModuleVersion = project.version as String doFirst { options.compilerArgs = [ '--module-path', classpath.asPath, '--patch-module', "org.spongepowered.mixin=${sourceSets["main"].output.collect { it.absolutePath }.join(File.pathSeparator)}" ] } } tasks.withType(Javadoc) { // disable the crazy super-strict doclint tool in Java 8 options.addStringOption('Xdoclint:syntax', '-quiet') } jar { dependsOn compileJava9Java dependsOn test // JAR manifest configuration manifest.attributes( "Built-By": System.properties['user.name'], "Created-By": System.properties['java.vm.version'] + " (" + System.properties['java.vm.vendor'] + ")", "Implementation-Title": name, "Implementation-Version": project.version, "Implementation-Vendor": url, // for hotswap agent "Premain-Class": "org.spongepowered.tools.agent.MixinAgent", "Agent-Class": "org.spongepowered.tools.agent.MixinAgent", "Can-Redefine-Classes": true, "Can-Retransform-Classes": true, "Multi-Release": true ) into('META-INF/LICENSES/' + base.archivesName.get()) { from project.rootProject.file("LICENSE.txt") } into('META-INF/versions/9') { from sourceSets.java9.output } } task sourcesJar(type: Jar, dependsOn: classes) { archiveClassifier = 'sources' from sourceSets.main.allSource into('META-INF/versions/9') { from sourceSets["java9"].allSource } into('META-INF/LICENSES/' + base.archivesName.get()) { from project.rootProject.file("LICENSE.txt") } } task javadocJar(type: Jar, dependsOn: javadoc) { archiveClassifier = 'javadoc' from javadoc.destinationDir } publishing { publications { maven(MavenPublication) { groupId = project.group artifactId = project.archivesBaseName from components['java'] artifact sourcesJar artifact javadocJar pom { name = "Stianloader Mixin" description = 'Stianloader Mixin is a fork of Fabric Mixin, which in turn is a fork of spongepowered Mixin, which is a high-level class transformation API.' url = 'https://github.com/stianloader/SLMixin' scm { connection = "scm:git:https://github.com/stianloader/SLMixin.git" developerConnection = "scm:git:git@github.com:stianloader/SLMixin.git" url = "https://github.com/stianloader/SLMixin" } issueManagement { system = "GitHub" url = "https://github.com/stianloader/SLMixin/issues" } licenses { license { name = 'The MIT License' url = 'https://opensource.org/licenses/MIT' distribution = 'repo' } } developers { // Et. al. that arent in the fabric org on maven central developer { id = "modmuss50" name = "modmuss50" email = "modmuss50@fabricmc.net" } developer { id = "sfPlayer" name = "Player" email = "player@fabricmc.net" } developer { id = 'geolykt' name = 'Emeric "Geolykt" Werner' email = 'mail@geolykt.de' timezone = 'Europe/Berlin' url = 'https://geolykt.de/' } } } } } repositories { if (providers.gradleProperty('publishRepo').isPresent()) { System.out.println("Publishing to " + providers.gradleProperty('publishRepo').get()) maven { url = providers.gradleProperty('publishRepo').get() allowInsecureProtocol = true } } else { System.out.println("Publishing to the local maven repository") mavenLocal() } } } if (providers.gradleProperty('signedPublish').isPresent() && Boolean.parseBoolean(providers.gradleProperty('signedPublish').get())) { signing { useGpgCmd() sign publishing.publications.maven } } publish.dependsOn(build)