Skip to content

Instantly share code, notes, and snippets.

@Lomeli12
Created February 2, 2022 02:38
Show Gist options
  • Save Lomeli12/9538b553e18d96d3d9a8c4f7683815c6 to your computer and use it in GitHub Desktop.
Save Lomeli12/9538b553e18d96d3d9a8c4f7683815c6 to your computer and use it in GitHub Desktop.
Custom task for multi-mod projects
// The following is a custom gradle task to make setting up a multimod project in IntelliJ less painful
// Setup a base project (I just use the examplemod from the MDK) and setup like normal. Then import your
// other mods as modules. Run the genIntelliJRuns task like normal, but then follow up with the updateRuns
// task written below, making sure to replace the items in the modProjects array with your own. It might
// also be a good idea to edit the run configurations in IntelliJ to build the whole project instead of just
// the base project (Edit Configuration -> For each run<blank> remove the "Build" step -> Click the + ->
// Add "Build Project" task -> drag to begining before "prepareRun<blank>" task)
def updateXMLRuns(String runName) {
def modProjects = [
["examplemod", ""], // This is just for the example mod in the MDK. Could always leave it out if you want
["trophyslots", "/../TrophySlots"],
["knit", "/../ForgeKnit"]
]
def runFile = file(".idea/runConfigurations/${runName}.xml")
if (runFile.exists()) {
def runParser = new XmlParser().parse(runFile)
runParser.configuration.envs.env.each { node ->
if (node.@name == "MOD_CLASSES") {
def newValue = ""
for (int i = 0; i < modProjects.size(); i++) {
def pair = modProjects[i]
if (newValue?.trim())
newValue += ":"
newValue += "${pair[0]}%%\$PROJECT_DIR\$${pair[1]}/build/resources/main:"
newValue += "${pair[0]}%%\$PROJECT_DIR\$${pair[1]}/build/classes/java/main"
}
node.@value = newValue
}
}
def writer = new FileWriter(runFile)
def printer = new XmlNodePrinter(new PrintWriter(writer))
printer.preserveWhitespace = true
printer.print(runParser)
}
}
task updateRuns {
updateXMLRuns("runClient")
updateXMLRuns("runData")
updateXMLRuns("runServer")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment