Here is how I modified it:

subprojects.each { evaluationDependsOn(it.path) }
subprojects {
        if (artifactType.equals('jar') || artifactType.equals('ejb')) {
                usePlugin('java')
                task compileUnitTests() << {
                        task ->
                        println task.project.getName() + " TODO: configure
the unit tests compilation..."
                }

                task testUnitTests(dependsOn: compileUnitTests) << {
                        task->
                        println task.project.getName() + "TODO: configure
unit tests..."
                }
        } else {
                throw new StopExecutionException("Unsupported artifact
type:${artifactType}, project:${name}")
        }
}

The only issue was that the subproject's build.gradle's are not evaluated
before the root build.gradle unless you explicitly request it.  Therefore,
the property was not being set.  So, the first line fixes that.  Other than
that, the ejb-session-module project now has two tasks compileUnitTests and
testUnitTests.  And any other module that defines an artifactType of 'jar'
or 'ejb' will also have those.  I removed the 'hasProperty' check because it
wasn't working and I don't understand why.  Regardless, you could just
try-catch the MissingPropertyException to get the old behavior back.

The last thing you might want to consider is having settings.gradle do a
little scan through a known directory and add all subdirectories as
subprojects.  This would mean that adding a new module to your system would
be as easy as creating a directory and dropping a build.gradle into it that
says "artifactType = 'jar'" or something.  That's more-or-less what we have
done here.


-- 
John Murph
Automated Logic Research Team

Reply via email to