Jump to content

[Solved][1.7.10] ForgeGradle, Groovy, and reobf


denoflions

Recommended Posts

When building a project written in Groovy ForgeGradle seems to have awareness of the fact that it is Groovy since it generates the appropriate tasks to compile it. However, the output doesn't seem to get reobf'd since I get an endless stream of 'No such property' errors any time I hit an obf'd field or method.

 

So unless I've done something wrong configuring my project, I assume getting a mod written in Groovy to load in an obf'd environment is impossible without a go-between java class or metaClass shenanigans. Am I wrong here?

 

edit: I've figured out the solution. You need to set every class that interacts with obf'd minecraft classes to CompileStatic. I wrote a hacky gradle task to accomplish this across the whole project automatically. Slap the following into your build.gradle and away you go.

 

task staticGroovy{

    def base = new File("src/main/groovy")

    base.eachFileRecurse {

        if (!it.isDirectory()){

            if (it.getName().contains(".groovy")){

                def bail = false

                def import_added = false

                def anno_added = false

                def list = [] as List<String>

                def marker = "//Preprocessed."

                def file = it

                list.add(marker)

                it.eachLine {

                    if (it.contains(marker)){

                        bail = true

                    }

                    def name = FilenameUtils.removeExtension(file.getName())

                    if (it.contains("class ${name}") && it.contains("{") && !anno_added){

                        list.add("@CompileStatic")

                        anno_added = true

                    }

                    list.add(it)

                    if (it.contains("package ") && !import_added){

                        list.add("")

                        list.add("import groovy.transform.CompileStatic")

                        import_added = true

                    }

                }

                if (!bail){

                    BufferedWriter out = new BufferedWriter(new FileWriter(it))

                    list.each{

                        out.write(it)

                        out.newLine()

                    }

                    out.flush()

                    out.close()

                }

            }

        }

    }

}

 

sourceMainGroovy.dependsOn staticGroovy

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.