diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index b80ca0bb3..7e9c4587b 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -27,6 +27,10 @@ gradlePlugin { plugin.id = 'flywheel.jar-sets' plugin.implementationClass = 'com.jozufozu.gradle.JarSetPlugin' } + packageInfosPlugin { PluginDeclaration plugin -> + plugin.id = 'flywheel.package-infos' + plugin.implementationClass = 'com.jozufozu.gradle.PackageInfosPlugin' + } } } diff --git a/buildSrc/src/main/groovy/GeneratePackageInfosTask.groovy b/buildSrc/src/main/groovy/com/jozufozu/gradle/GeneratePackageInfosTask.groovy similarity index 98% rename from buildSrc/src/main/groovy/GeneratePackageInfosTask.groovy rename to buildSrc/src/main/groovy/com/jozufozu/gradle/GeneratePackageInfosTask.groovy index dbb693f74..e3e34cf15 100644 --- a/buildSrc/src/main/groovy/GeneratePackageInfosTask.groovy +++ b/buildSrc/src/main/groovy/com/jozufozu/gradle/GeneratePackageInfosTask.groovy @@ -1,3 +1,5 @@ +package com.jozufozu.gradle + import org.gradle.api.DefaultTask import org.gradle.api.file.DirectoryProperty import org.gradle.api.tasks.InputDirectory diff --git a/buildSrc/src/main/groovy/com/jozufozu/gradle/JarSetExtension.groovy b/buildSrc/src/main/groovy/com/jozufozu/gradle/JarSetExtension.groovy new file mode 100644 index 000000000..733761a64 --- /dev/null +++ b/buildSrc/src/main/groovy/com/jozufozu/gradle/JarSetExtension.groovy @@ -0,0 +1,23 @@ +package com.jozufozu.gradle + +import groovy.transform.CompileStatic +import org.gradle.api.Project +import org.gradle.api.tasks.SourceSet +import org.gradle.api.tasks.SourceSetContainer + +@CompileStatic +class JarSetExtension { + private final Project project + + JarSetExtension(Project project) { + this.project = project + } + + JarTaskSet createJars(String name) { + return createJars(name, project.getExtensions().getByType(SourceSetContainer).named(name).get()) + } + + JarTaskSet createJars(String name, SourceSet... sourceSetSet) { + return JarTaskSet.create(project, name, sourceSetSet) + } +} diff --git a/buildSrc/src/main/groovy/com/jozufozu/gradle/JarSetPlugin.groovy b/buildSrc/src/main/groovy/com/jozufozu/gradle/JarSetPlugin.groovy index 4fc44a19a..50b572565 100644 --- a/buildSrc/src/main/groovy/com/jozufozu/gradle/JarSetPlugin.groovy +++ b/buildSrc/src/main/groovy/com/jozufozu/gradle/JarSetPlugin.groovy @@ -4,30 +4,12 @@ package com.jozufozu.gradle import groovy.transform.CompileStatic import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.api.tasks.SourceSet -import org.gradle.api.tasks.SourceSetContainer @CompileStatic class JarSetPlugin implements Plugin { @Override void apply(Project project) { - project.extensions.create("jarSets", JarSetExtension, project) + project.extensions.create('jarSets', JarSetExtension, project) } } -@CompileStatic -class JarSetExtension { - private final Project project - - JarSetExtension(Project project) { - this.project = project - } - - JarTaskSet createJars(String name) { - return createJars(name, project.getExtensions().getByType(SourceSetContainer).named(name).get()) - } - - JarTaskSet createJars(String name, SourceSet... sourceSetSet) { - return JarTaskSet.create(project, name, sourceSetSet) - } -} diff --git a/buildSrc/src/main/groovy/com/jozufozu/gradle/PackageInfosExtension.groovy b/buildSrc/src/main/groovy/com/jozufozu/gradle/PackageInfosExtension.groovy new file mode 100644 index 000000000..cecc3f80a --- /dev/null +++ b/buildSrc/src/main/groovy/com/jozufozu/gradle/PackageInfosExtension.groovy @@ -0,0 +1,50 @@ +package com.jozufozu.gradle + +import groovy.transform.CompileStatic +import org.gradle.api.Project +import org.gradle.api.tasks.Delete +import org.gradle.api.tasks.SourceSet + +@CompileStatic +class PackageInfosExtension { + final Project project + + PackageInfosExtension(Project project) { + this.project = project + } + + void forSourceSets(SourceSet... sourceSets) { + for (SourceSet sourceSet : sourceSets) { + _forSourceSet(sourceSet) + } + } + + private void _forSourceSet(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 = project.tasks.register(taskName, GeneratePackageInfosTask) { + it.group = 'flywheel' + it.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. + it.sourceRoot.set(project.file("src/$sourceSetName/java")) + it.outputDir.set(project.file("src/$sourceSetName/generatedPackageInfos")) + } + sourceSet.java.srcDir(task) + + project.tasks.named('ideaSyncTask').configure { + it.finalizedBy(task) + } + + def cleanTask = project.tasks.register(sourceSet.getTaskName('clean', 'PackageInfos'), Delete) { + it.group = 'flywheel' + it.delete(project.file("src/$sourceSetName/generatedPackageInfos")) + } + project.tasks.named('clean').configure { + it.dependsOn(cleanTask) + } + } +} diff --git a/buildSrc/src/main/groovy/com/jozufozu/gradle/PackageInfosPlugin.groovy b/buildSrc/src/main/groovy/com/jozufozu/gradle/PackageInfosPlugin.groovy new file mode 100644 index 000000000..8e6435d8f --- /dev/null +++ b/buildSrc/src/main/groovy/com/jozufozu/gradle/PackageInfosPlugin.groovy @@ -0,0 +1,14 @@ +package com.jozufozu.gradle + +import groovy.transform.CompileStatic +import org.gradle.api.Plugin +import org.gradle.api.Project + +@CompileStatic +class PackageInfosPlugin implements Plugin { + @Override + void apply(Project target) { + target.extensions.create('defaultPackageInfos', PackageInfosExtension, target) + } +} + diff --git a/buildSrc/src/main/groovy/flywheel.package-infos.gradle b/buildSrc/src/main/groovy/flywheel.package-infos.gradle deleted file mode 100644 index 1e9392da6..000000000 --- a/buildSrc/src/main/groovy/flywheel.package-infos.gradle +++ /dev/null @@ -1,31 +0,0 @@ - -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/common/build.gradle b/common/build.gradle index 66d8d4292..0181025c8 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -40,6 +40,10 @@ sourceSets { } } +defaultPackageInfos { + forSourceSets sourceSets.api, sourceSets.lib, sourceSets.backend, sourceSets.main +} + // For sharing with other subprojects. jarSets { createJars('apiOnly', sourceSets.api).configure { diff --git a/fabric/build.gradle b/fabric/build.gradle index 4ae964468..e975b7754 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -11,6 +11,10 @@ plugins { evaluationDependsOn(':common') +defaultPackageInfos { + forSourceSets sourceSets.api, sourceSets.lib, sourceSets.backend, sourceSets.main +} + loom { runs { client { diff --git a/forge/build.gradle b/forge/build.gradle index b6ef3166c..97a812da3 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -11,6 +11,10 @@ plugins { evaluationDependsOn(':common') +defaultPackageInfos { + forSourceSets sourceSets.api, sourceSets.lib, sourceSets.backend, sourceSets.main +} + loom { forge { mixinConfig 'flywheel.backend.mixins.json'