diff --git a/build.gradle b/build.gradle index 9f9460aad..30891b8f7 100644 --- a/build.gradle +++ b/build.gradle @@ -5,8 +5,6 @@ plugins { id 'dev.architectury.loom' apply false } -apply from: rootProject.file('buildSrc/simple-java.gradle') - println("Java: ${System.getProperty('java.version')}, JVM: ${System.getProperty('java.vm.version')} (${System.getProperty('java.vendor')}), Arch: ${System.getProperty('os.arch')}") idea { diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index a42435e5e..678405245 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -1,2 +1,3 @@ - -// TODO: port stuff to convention plugins +plugins { + id 'groovy-gradle-plugin' +} diff --git a/buildSrc/package-infos.gradle b/buildSrc/package-infos.gradle deleted file mode 100644 index 1fd334292..000000000 --- a/buildSrc/package-infos.gradle +++ /dev/null @@ -1,74 +0,0 @@ -// Adapted from https://github.com/FabricMC/fabric/blob/31787236d242247e0b6c4ae806b1cfaa7042a62c/gradle/package-info.gradle, which is licensed under Apache 2.0. - -import java.nio.file.Files - -setupGeneratePackageInfos(sourceSets.main) - -def setupGeneratePackageInfos(SourceSet sourceSet) { - // We have to capture the source set name for the lazy string literals, - // otherwise it'll just be whatever the last source set is in the list. - def sourceSetName = sourceSet.name - def taskName = sourceSet.getTaskName('generate', 'PackageInfos') - def task = tasks.register(taskName, GeneratePackageInfosTask) { - group = 'flywheel' - description = "Generates package-info files for $sourceSetName packages." - - // Only apply to default source directory since we also add the generated - // sources to the source set. - sourceRoot = file("src/$sourceSetName/java") - outputDir = file("src/$sourceSetName/generatedPackageInfos") - } - sourceSet.java.srcDir task - - tasks.named('ideaSyncTask').configure { - finalizedBy task - } - - def cleanTask = tasks.register(sourceSet.getTaskName('clean', 'PackageInfos'), Delete) { - group = 'flywheel' - delete file("src/$sourceSetName/generatedPackageInfos") - } - clean.dependsOn cleanTask -} - -class GeneratePackageInfosTask extends DefaultTask { - @SkipWhenEmpty - @InputDirectory - final DirectoryProperty sourceRoot = project.objects.directoryProperty() - - @OutputDirectory - final DirectoryProperty outputDir = project.objects.directoryProperty() - - @TaskAction - def run() { - def output = outputDir.get().asFile.toPath() - output.deleteDir() - def root = sourceRoot.get().asFile.toPath() - - root.eachDirRecurse { - def containsJava = Files.list(it).any { - Files.isRegularFile(it) && it.fileName.toString().endsWith('.java') - } - - if (containsJava && Files.notExists(it.resolve('package-info.java'))) { - def relativePath = root.relativize(it) - def target = output.resolve(relativePath) - Files.createDirectories(target) - - target.resolve('package-info.java').withWriter { - def packageName = relativePath.toString().replace(File.separator, '.') - it.write("""@ParametersAreNonnullByDefault - |@FieldsAreNonnullByDefault - |@MethodsReturnNonnullByDefault - |package $packageName; - | - |import javax.annotation.ParametersAreNonnullByDefault; - | - |import net.minecraft.FieldsAreNonnullByDefault; - |import net.minecraft.MethodsReturnNonnullByDefault; - |""".stripMargin()) - } - } - } - } -} diff --git a/buildSrc/src/main/groovy/GeneratePackageInfosTask.groovy b/buildSrc/src/main/groovy/GeneratePackageInfosTask.groovy new file mode 100644 index 000000000..36533a10a --- /dev/null +++ b/buildSrc/src/main/groovy/GeneratePackageInfosTask.groovy @@ -0,0 +1,53 @@ + + +import org.gradle.api.DefaultTask +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.tasks.InputDirectory +import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.SkipWhenEmpty +import org.gradle.api.tasks.TaskAction + +import java.nio.file.Files + +// Adapted from https://github.com/FabricMC/fabric/blob/31787236d242247e0b6c4ae806b1cfaa7042a62c/gradle/package-info.gradle, which is licensed under Apache 2.0. +class GeneratePackageInfosTask extends DefaultTask { + @SkipWhenEmpty + @InputDirectory + final DirectoryProperty sourceRoot = project.objects.directoryProperty() + + @OutputDirectory + final DirectoryProperty outputDir = project.objects.directoryProperty() + + @TaskAction + def run() { + def output = outputDir.get().asFile.toPath() + output.deleteDir() + def root = sourceRoot.get().asFile.toPath() + + root.eachDirRecurse { + def containsJava = Files.list(it).any { + Files.isRegularFile(it) && it.fileName.toString().endsWith('.java') + } + + if (containsJava && Files.notExists(it.resolve('package-info.java'))) { + def relativePath = root.relativize(it) + def target = output.resolve(relativePath) + Files.createDirectories(target) + + target.resolve('package-info.java').withWriter { + def packageName = relativePath.toString().replace(File.separator, '.') + it.write("""@ParametersAreNonnullByDefault + |@FieldsAreNonnullByDefault + |@MethodsReturnNonnullByDefault + |package $packageName; + | + |import javax.annotation.ParametersAreNonnullByDefault; + | + |import net.minecraft.FieldsAreNonnullByDefault; + |import net.minecraft.MethodsReturnNonnullByDefault; + |""".stripMargin()) + } + } + } + } +} diff --git a/buildSrc/simple-java.gradle b/buildSrc/src/main/groovy/flywheel.java.gradle similarity index 98% rename from buildSrc/simple-java.gradle rename to buildSrc/src/main/groovy/flywheel.java.gradle index e74eba5e9..0aa594e6e 100644 --- a/buildSrc/simple-java.gradle +++ b/buildSrc/src/main/groovy/flywheel.java.gradle @@ -1,3 +1,7 @@ +plugins { + id 'java' +} + boolean dev = System.getenv('RELEASE') == null || System.getenv('RELEASE').equalsIgnoreCase('false') String buildNumber = System.getenv('BUILD_NUMBER') diff --git a/buildSrc/src/main/groovy/flywheel.package-infos.gradle b/buildSrc/src/main/groovy/flywheel.package-infos.gradle new file mode 100644 index 000000000..1e9392da6 --- /dev/null +++ b/buildSrc/src/main/groovy/flywheel.package-infos.gradle @@ -0,0 +1,31 @@ + +sourceSets.configureEach { + setupGeneratePackageInfos(it) +} + +def setupGeneratePackageInfos(SourceSet sourceSet) { + // We have to capture the source set name for the lazy string literals, + // otherwise it'll just be whatever the last source set is in the list. + def sourceSetName = sourceSet.name + def taskName = sourceSet.getTaskName('generate', 'PackageInfos') + def task = tasks.register(taskName, GeneratePackageInfosTask) { + group = 'flywheel' + description = "Generates package-info files for $sourceSetName packages." + + // Only apply to default source directory since we also add the generated + // sources to the source set. + sourceRoot = file("src/$sourceSetName/java") + outputDir = file("src/$sourceSetName/generatedPackageInfos") + } + sourceSet.java.srcDir task + + tasks.named('ideaSyncTask').configure { + finalizedBy task + } + + def cleanTask = tasks.register(sourceSet.getTaskName('clean', 'PackageInfos'), Delete) { + group = 'flywheel' + delete file("src/$sourceSetName/generatedPackageInfos") + } + clean.dependsOn cleanTask +} diff --git a/buildSrc/platforms.gradle b/buildSrc/src/main/groovy/flywheel.platform.gradle similarity index 98% rename from buildSrc/platforms.gradle rename to buildSrc/src/main/groovy/flywheel.platform.gradle index 19e7feddb..84a73a2a1 100644 --- a/buildSrc/platforms.gradle +++ b/buildSrc/src/main/groovy/flywheel.platform.gradle @@ -1,3 +1,7 @@ +plugins { + id 'flywheel.subproject' +} + evaluationDependsOn(':common') loom { diff --git a/buildSrc/subprojects.gradle b/buildSrc/src/main/groovy/flywheel.subproject.gradle similarity index 93% rename from buildSrc/subprojects.gradle rename to buildSrc/src/main/groovy/flywheel.subproject.gradle index 4d87d9606..e7ee6cd41 100644 --- a/buildSrc/subprojects.gradle +++ b/buildSrc/src/main/groovy/flywheel.subproject.gradle @@ -1,3 +1,11 @@ +plugins { + id 'idea' + id 'flywheel.java' + id 'maven-publish' + id 'dev.architectury.loom' + id 'flywheel.package-infos' +} + loom { silentMojangMappingsLicense() diff --git a/common/build.gradle b/common/build.gradle index 802838ba7..51970de5b 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -1,15 +1,7 @@ plugins { - id 'idea' - id 'java' - id 'maven-publish' - id 'dev.architectury.loom' + id 'flywheel.subproject' } -apply from: rootProject.file('buildSrc/simple-java.gradle') -apply from: rootProject.file('buildSrc/subprojects.gradle') -// TODO: package-infos specifically targets the main source set -// apply from: rootProject.file('buildSrc/package-infos.gradle') - sourceSets { // Loom only populates mc stuff to the main source set, // so grab that here and use it for the others. diff --git a/fabric/build.gradle b/fabric/build.gradle index e1e426b0e..c9262ed2c 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -1,15 +1,7 @@ plugins { - id 'idea' - id 'java' - id 'maven-publish' - id 'dev.architectury.loom' + id 'flywheel.platform' } -apply from: rootProject.file('buildSrc/simple-java.gradle') -apply from: rootProject.file('buildSrc/subprojects.gradle') -apply from: rootProject.file('buildSrc/platforms.gradle') -apply from: rootProject.file('buildSrc/package-infos.gradle') - dependencies { modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}" modApi "net.fabricmc.fabric-api:fabric-api:${fabric_api_version}" diff --git a/forge/build.gradle b/forge/build.gradle index 7066b5c65..79882c90c 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -1,15 +1,7 @@ plugins { - id 'idea' - id 'java' - id 'maven-publish' - id 'dev.architectury.loom' + id 'flywheel.platform' } -apply from: rootProject.file('buildSrc/simple-java.gradle') -apply from: rootProject.file('buildSrc/subprojects.gradle') -apply from: rootProject.file('buildSrc/platforms.gradle') -apply from: rootProject.file('buildSrc/package-infos.gradle') - loom { forge { mixinConfig 'flywheel.backend.mixins.json'