mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-01-12 23:36:09 +01:00
Unconventional
- Use convention plugins for common build logic - Convention plugins get to be applied in the plugins block and can load other plugins - Move GeneratePackageInfosTask to its own file in buildSrc - Apply GeneratePackageInfosTask to every sourceSet
This commit is contained in:
parent
82a098626b
commit
e1b0cebc2c
11 changed files with 106 additions and 105 deletions
|
@ -5,8 +5,6 @@ plugins {
|
||||||
id 'dev.architectury.loom' apply false
|
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')}")
|
println("Java: ${System.getProperty('java.version')}, JVM: ${System.getProperty('java.vm.version')} (${System.getProperty('java.vendor')}), Arch: ${System.getProperty('os.arch')}")
|
||||||
|
|
||||||
idea {
|
idea {
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
|
plugins {
|
||||||
// TODO: port stuff to convention plugins
|
id 'groovy-gradle-plugin'
|
||||||
|
}
|
||||||
|
|
|
@ -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())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
53
buildSrc/src/main/groovy/GeneratePackageInfosTask.groovy
Normal file
53
buildSrc/src/main/groovy/GeneratePackageInfosTask.groovy
Normal file
|
@ -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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,3 +1,7 @@
|
||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
}
|
||||||
|
|
||||||
boolean dev = System.getenv('RELEASE') == null || System.getenv('RELEASE').equalsIgnoreCase('false')
|
boolean dev = System.getenv('RELEASE') == null || System.getenv('RELEASE').equalsIgnoreCase('false')
|
||||||
String buildNumber = System.getenv('BUILD_NUMBER')
|
String buildNumber = System.getenv('BUILD_NUMBER')
|
||||||
|
|
31
buildSrc/src/main/groovy/flywheel.package-infos.gradle
Normal file
31
buildSrc/src/main/groovy/flywheel.package-infos.gradle
Normal file
|
@ -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
|
||||||
|
}
|
|
@ -1,3 +1,7 @@
|
||||||
|
plugins {
|
||||||
|
id 'flywheel.subproject'
|
||||||
|
}
|
||||||
|
|
||||||
evaluationDependsOn(':common')
|
evaluationDependsOn(':common')
|
||||||
|
|
||||||
loom {
|
loom {
|
|
@ -1,3 +1,11 @@
|
||||||
|
plugins {
|
||||||
|
id 'idea'
|
||||||
|
id 'flywheel.java'
|
||||||
|
id 'maven-publish'
|
||||||
|
id 'dev.architectury.loom'
|
||||||
|
id 'flywheel.package-infos'
|
||||||
|
}
|
||||||
|
|
||||||
loom {
|
loom {
|
||||||
silentMojangMappingsLicense()
|
silentMojangMappingsLicense()
|
||||||
|
|
|
@ -1,15 +1,7 @@
|
||||||
plugins {
|
plugins {
|
||||||
id 'idea'
|
id 'flywheel.subproject'
|
||||||
id 'java'
|
|
||||||
id 'maven-publish'
|
|
||||||
id 'dev.architectury.loom'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
sourceSets {
|
||||||
// Loom only populates mc stuff to the main source set,
|
// Loom only populates mc stuff to the main source set,
|
||||||
// so grab that here and use it for the others.
|
// so grab that here and use it for the others.
|
||||||
|
|
|
@ -1,15 +1,7 @@
|
||||||
plugins {
|
plugins {
|
||||||
id 'idea'
|
id 'flywheel.platform'
|
||||||
id 'java'
|
|
||||||
id 'maven-publish'
|
|
||||||
id 'dev.architectury.loom'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
dependencies {
|
||||||
modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}"
|
modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}"
|
||||||
modApi "net.fabricmc.fabric-api:fabric-api:${fabric_api_version}"
|
modApi "net.fabricmc.fabric-api:fabric-api:${fabric_api_version}"
|
||||||
|
|
|
@ -1,15 +1,7 @@
|
||||||
plugins {
|
plugins {
|
||||||
id 'idea'
|
id 'flywheel.platform'
|
||||||
id 'java'
|
|
||||||
id 'maven-publish'
|
|
||||||
id 'dev.architectury.loom'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
loom {
|
||||||
forge {
|
forge {
|
||||||
mixinConfig 'flywheel.backend.mixins.json'
|
mixinConfig 'flywheel.backend.mixins.json'
|
||||||
|
|
Loading…
Reference in a new issue