crotwell / gradle-macappbundle

A Gradle Plugin to create a Mac OSX .app application and dmg based on the project.
Apache License 2.0
94 stars 33 forks source link

Subproject evalutation and executing project.afterEvaluate{} #48

Closed mgroth0 closed 6 years ago

mgroth0 commented 6 years ago

A recursive task search in plugin.apply causes early evaluation of subprojects.

I was having an issue in a multiproject build where a subproject's app was not copying lib jars into the .app.

Finally, I tracked down the cause. The following block in MacAppBundle.groovy needs to be put inside a project.afterEvaluate block:

 if (Os.isFamily(Os.FAMILY_MAC)) {
    project.getTasksByName("assemble", true).each{ t -> t.dependsOn(dmgTask) }
} else {
    project.getTasksByName("assemble", true).each{ t -> t.dependsOn(zipTask) }
}

Putting this inside an afterEvaluate solved all my problems. I guess the recursive task search forces an early evaluation of subprojects. Then when addCopyToLibTask() is called this block doesn't get called in the subproject since its already evaluated.

project.afterEvaluate {
            task.with configureDistSpec(project)
        }

My solution feels like more of a workaround though. Shouldn't gradle execute project.afterEvaluate blocks for projects that were already evaluated before? I did a lot of testing and it seems that afterEvaluate must be called before the project is evaluated...

crotwell commented 6 years ago

Done in commit a40fff83c919fe9a4ac0ba815cb338cc0a8d765a will be in 2.1.8 when I release it. Please have a look and let me know if it seems correct.

thanks for reporting this.