Skip to content

Commit

Permalink
RFG IntelliJ fixes (GTNewHorizons#133)
Browse files Browse the repository at this point in the history
* Bump GTNHmixins

* Bump RFG version

* Add a global override for the IDEA build type

* Support multiple access transformer files

* Move mavenLocal last in the buildscript repos to fix plugin caching

* Update RFG to 1.2.0

* Make username settings work again

* Update lwjgl3ify

* Update lwjgl3 version to 3.3.2-SNAPSHOT

* Add default IDEA project output path, compatible with both ipr and .idea projects

Closes GTNewHorizons#132

* Update Gradle to 8.0 on buildscript updates

* Update gradle to 8.0

* Bump version

* Gradle 8.0.1

* Fix derp with "relocate/minimize dependencies" properties
  • Loading branch information
eigenraven authored Feb 20, 2023
1 parent 898f9d8 commit edba06d
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 20 deletions.
128 changes: 110 additions & 18 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//version: 1676679815
//version: 1676715412
/*
DO NOT CHANGE THIS FILE!
Also, you may replace this file at any time if there is an update available.
Expand All @@ -20,6 +20,7 @@ import cpw.mods.fml.relauncher.Side
import org.gradle.api.tasks.options.Option;
import org.gradle.internal.logging.text.StyledTextOutput.Style
import org.gradle.internal.logging.text.StyledTextOutputFactory
import org.gradle.internal.xml.XmlTransformer
import org.jetbrains.gradle.ext.*

import java.nio.file.Files
Expand All @@ -31,7 +32,6 @@ import javax.inject.Inject

buildscript {
repositories {
mavenLocal()
mavenCentral()

maven {
Expand All @@ -52,6 +52,8 @@ buildscript {
name 'Scala CI dependencies'
url 'https://repo1.maven.org/maven2/'
}

mavenLocal()
}
}
plugins {
Expand All @@ -71,7 +73,7 @@ plugins {
id 'com.diffplug.spotless' version '6.7.2' apply false
id 'com.modrinth.minotaur' version '2.+' apply false
id 'com.matthewprenger.cursegradle' version '1.4.0' apply false
id 'com.gtnewhorizons.retrofuturagradle' version '1.1.6'
id 'com.gtnewhorizons.retrofuturagradle' version '1.2.1'
}
boolean settingsupdated = verifySettingsGradle()
settingsupdated = verifyGitAttributes() || settingsupdated
Expand Down Expand Up @@ -127,6 +129,9 @@ propertyDefaultIfUnset("gradleTokenGroupName", "")
propertyDefaultIfUnset("enableModernJavaSyntax", false) // On by default for new projects only
propertyDefaultIfUnset("enableGenericInjection", false) // On by default for new projects only

// this is meant to be set using the user wide property file. by default we do nothing.
propertyDefaultIfUnset("ideaOverrideBuildType", "") // Can be nothing, "gradle" or "idea"

project.extensions.add(Blowdryer, "Blowdryer", Blowdryer) // Make blowdryer available in "apply from:" scripts
if (!disableSpotless) {
apply plugin: 'com.diffplug.spotless'
Expand Down Expand Up @@ -249,12 +254,14 @@ if (apiPackage) {
}

if (accessTransformersFile) {
String targetFile = "src/main/resources/META-INF/" + accessTransformersFile
if (!getFile(targetFile).exists()) {
throw new GradleException("Could not resolve \"accessTransformersFile\"! Could not find " + targetFile)
for (atFile in accessTransformersFile.split(",")) {
String targetFile = "src/main/resources/META-INF/" + atFile.trim()
if (!getFile(targetFile).exists()) {
throw new GradleException("Could not resolve \"accessTransformersFile\"! Could not find " + targetFile)
}
tasks.deobfuscateMergedJarToSrg.accessTransformerFiles.from(targetFile)
tasks.srgifyBinpatchedJar.accessTransformerFiles.from(targetFile)
}
tasks.deobfuscateMergedJarToSrg.accessTransformerFiles.from(targetFile)
tasks.srgifyBinpatchedJar.accessTransformerFiles.from(targetFile)
} else {
boolean atsFound = false
for (File at : sourceSets.getByName("main").resources.files) {
Expand Down Expand Up @@ -382,6 +389,10 @@ minecraft {
injectMissingGenerics.set(true)
}

username = developmentEnvironmentUserName.toString()

lwjgl3Version = "3.3.2-SNAPSHOT"

// Enable assertions in the current mod
extraRunJvmArguments.add("-ea:${modGroup}")

Expand Down Expand Up @@ -509,6 +520,13 @@ repositories {
}
}
}
maven {
name 'sonatype'
url 'https://oss.sonatype.org/content/repositories/snapshots/'
content {
includeGroup "org.lwjgl"
}
}
if (includeWellKnownRepositories.toBoolean()) {
maven {
name "CurseMaven"
Expand Down Expand Up @@ -545,20 +563,20 @@ dependencies {
annotationProcessor('org.ow2.asm:asm-debug-all:5.0.3')
annotationProcessor('com.google.guava:guava:24.1.1-jre')
annotationProcessor('com.google.code.gson:gson:2.8.6')
annotationProcessor('com.gtnewhorizon:gtnhmixins:2.1.12:processor')
annotationProcessor('com.gtnewhorizon:gtnhmixins:2.1.13:processor')
if (usesMixinDebug.toBoolean()) {
runtimeOnlyNonPublishable('org.jetbrains:intellij-fernflower:1.2.1.16')
}
}
if (usesMixins.toBoolean() || forceEnableMixins.toBoolean()) {
implementation('com.gtnewhorizon:gtnhmixins:2.1.12')
implementation('com.gtnewhorizon:gtnhmixins:2.1.13')
}
}

pluginManager.withPlugin('org.jetbrains.kotlin.kapt') {
if (usesMixins.toBoolean()) {
dependencies {
kapt('com.gtnewhorizon:gtnhmixins:2.1.12:processor')
kapt('com.gtnewhorizon:gtnhmixins:2.1.13:processor')
}
}
}
Expand Down Expand Up @@ -671,7 +689,7 @@ ext.java17DependenciesCfg = configurations.create("java17Dependencies")
ext.java17PatchDependenciesCfg = configurations.create("java17PatchDependencies")

dependencies {
def lwjgl3ifyVersion = '1.1.21'
def lwjgl3ifyVersion = '1.1.28'
def asmVersion = '9.4'
if (modId != 'lwjgl3ify') {
java17Dependencies("com.github.GTNewHorizons:lwjgl3ify:${lwjgl3ifyVersion}")
Expand Down Expand Up @@ -750,8 +768,8 @@ public abstract class RunHotswappableMinecraftTask extends RunMinecraftTask {
public boolean setEnableHotswap(boolean enable) { enableHotswap = enable }

@Inject
public RunHotswappableMinecraftTask(Side side, String superTask) {
super(side)
public RunHotswappableMinecraftTask(Side side, String superTask, org.gradle.api.invocation.Gradle gradle) {
super(side, gradle)

this.lwjglVersion = 3
this.javaLauncher = project.javaToolchains.launcherFor(project.java17Toolchain)
Expand Down Expand Up @@ -782,6 +800,8 @@ runClient17Task.configure {
description = "Runs the modded client using Java 17, lwjgl3ify and Hodgepodge"
dependsOn(setupHotswapAgentTask, mcpTasks.launcherSources.classesTaskName, minecraftTasks.taskDownloadVanillaAssets, mcpTasks.taskPackagePatchedMc, 'jar')
mainClass = "GradleStart"
username = minecraft.username
userUUID = minecraft.userUUID
}

def runServer17Task = tasks.register("runServer17", RunHotswappableMinecraftTask, Side.SERVER, "runServer")
Expand Down Expand Up @@ -828,7 +848,7 @@ if (usesShadowedDependencies.toBoolean()) {
tasks.register('relocateShadowJar', ConfigureShadowRelocation) {
target = tasks.shadowJar
prefix = modGroup + ".shadow"
enabled = minimizeShadowedDependencies.toBoolean()
enabled = relocateShadowedDependencies.toBoolean()
}
tasks.named("shadowJar", ShadowJar).configure {
manifest {
Expand All @@ -844,7 +864,7 @@ if (usesShadowedDependencies.toBoolean()) {
project.configurations.shadeCompile
]
archiveClassifier.set('dev')
if (minimizeShadowedDependencies.toBoolean()) {
if (relocateShadowedDependencies.toBoolean()) {
dependsOn(relocateShadowJar)
}
}
Expand Down Expand Up @@ -905,6 +925,19 @@ idea {
}
project {
settings {
if (ideaOverrideBuildType != "") {
delegateActions {
if ("gradle".equalsIgnoreCase(ideaOverrideBuildType)) {
delegateBuildRunToGradle = true
testRunner = org.jetbrains.gradle.ext.ActionDelegationConfig.TestRunner.GRADLE
} else if ("idea".equalsIgnoreCase(ideaOverrideBuildType)) {
delegateBuildRunToGradle = false
testRunner = org.jetbrains.gradle.ext.ActionDelegationConfig.TestRunner.PLATFORM
} else {
throw GradleScriptException('Accepted value for ideaOverrideBuildType is one of gradle or idea.')
}
}
}
runConfigurations {
"1. Run Client"(Gradle) {
taskNames = ["runClient"]
Expand Down Expand Up @@ -943,7 +976,7 @@ idea {
}
"Run Client (IJ Native)"(Application) {
mainClass = "GradleStart"
moduleName = project.name + ".main"
moduleName = project.name + ".ideVirtualMain"
afterEvaluate {
workingDirectory = tasks.runClient.workingDir.absolutePath
programParameters = tasks.runClient.calculateArgs(project).collect { '"' + it + '"' }.join(' ')
Expand All @@ -954,7 +987,7 @@ idea {
}
"Run Server (IJ Native)"(Application) {
mainClass = "GradleStartServer"
moduleName = project.name + ".main"
moduleName = project.name + ".ideVirtualMain"
afterEvaluate {
workingDirectory = tasks.runServer.workingDir.absolutePath
programParameters = tasks.runServer.calculateArgs(project).collect { '"' + it + '"' }.join(' ')
Expand All @@ -971,6 +1004,51 @@ idea {
]
}
}
withIDEADir { File ideaDir ->
if (!ideaDir.path.contains(".idea")) {
// If an .ipr file exists, the project root directory is passed here instead of the .idea subdirectory
ideaDir = new File(ideaDir, ".idea")
}
if (ideaDir.isDirectory()) {
def miscFile = new File(ideaDir, "misc.xml")
if (miscFile.isFile()) {
boolean dirty = false
def miscTransformer = new XmlTransformer()
miscTransformer.addAction { root ->
Node rootNode = root.asNode()
def rootManager = rootNode
.component.find { it.@name == 'ProjectRootManager' }
if (!rootManager) {
rootManager = rootNode.appendNode('component', ['name': 'ProjectRootManager', 'version': '2'])
dirty = true
}
def output = rootManager.output
if (!output) {
output = rootManager.appendNode('output')
dirty = true
}
if (!output.@url) {
// Only modify the output url if it doesn't yet have one, or if the existing one is blank somehow.
// This is a sensible default for most setups
output.@url = 'file://$PROJECT_DIR$/build/ideaBuild'
dirty = true
}
}
def result = miscTransformer.transform(miscFile.text)
if (dirty) {
miscFile.write(result)
}
} else {
miscFile.text = """<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2">
<output url="file://\$PROJECT_DIR\$/out" />
</component>
</project>
"""
}
}
}
}
}
}
Expand Down Expand Up @@ -1118,10 +1196,21 @@ def addCurseForgeRelation(String type, String name) {
}

// Updating

def buildscriptGradleVersion = "8.0.1"

tasks.named('wrapper', Wrapper).configure {
gradleVersion = buildscriptGradleVersion
}

tasks.register('updateBuildScript') {
group = 'GTNH Buildscript'
description = 'Updates the build script to the latest version'

if (gradle.gradleVersion != buildscriptGradleVersion && !Boolean.getBoolean('DISABLE_BUILDSCRIPT_GRADLE_UPDATE')) {
dependsOn('wrapper')
}

doLast {
if (performBuildScriptUpdate()) return

Expand All @@ -1134,6 +1223,9 @@ if (!project.getGradle().startParameter.isOffline() && !Boolean.getBoolean('DISA
performBuildScriptUpdate()
} else {
out.style(Style.SuccessHeader).println("Build script update available! Run 'gradle updateBuildScript'")
if (gradle.gradleVersion != buildscriptGradleVersion) {
out.style(Style.SuccessHeader).println("updateBuildScript can update gradle from ${gradle.gradleVersion} to ${buildscriptGradleVersion}\n")
}
}
}

Expand Down
11 changes: 10 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ replaceGradleTokenInFile =
apiPackage =

# Specify the configuration file for Forge's access transformers here. It must be placed into /src/main/resources/META-INF/
# Example value: mymodid_at.cfg
# There can be multiple files in a comma-separated list.
# Example value: mymodid_at.cfg,nei_at.cfg
accessTransformersFile =

# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
Expand Down Expand Up @@ -132,3 +133,11 @@ curseForgeRelations =
# This should only be uncommented to keep it easier to sync with upstream/other forks.
# That is, if there is no other active fork/upstream, NEVER change this.
# disableSpotless = true

# Override the IDEA build type. Valid value is "" (leave blank, do not override), "idea" (force use native IDEA build), "gradle"
# (force use delegated build).
# This is meant to be set in $HOME/.gradle/gradle.properties.
# e.g. add "systemProp.org.gradle.project.ideaOverrideBuildType=idea" will override the build type to be always native build.
# WARNING: If you do use this option, it will overwrite whatever you have in your existing projects. This might not be what you want!
# Usually there is no need to uncomment this here as other developers do not necessarily use the same build type as you.
# ideaOverrideBuildType = idea
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit edba06d

Please sign in to comment.