I have a multi project build that results in a WAR file that i am trying to
manage with gradle. The goal is to have a war thats buildable with gradle
and be able to deploy and test app via eclipse's tomcat integration at the
same time. The secondary goal is for other developers on the project not
having to generate or change any eclipse settings to get this done (beyond
creating a new server in the server tab).

I've set up build.gradle files in all sub projects and a master project with
the main settings and build file as well. I got gradle to generate a working
war file and eclipse project files for all subprojects. Most of these work
very well, all dependencies are reflected in the class path and project
references. One problem i am running into is on the sub project which holds
the web app. It is being build using the war plugin in gradle and has the
following settings via the build.gradle file:

import org.gradle.api.tasks.ide.eclipse.ProjectType;

usePlugin('war')

eclipseProject {
  projectName = 'web'
  projectType = ProjectType.WTP_WEBAPP
}

eclipseWtp {
  deployName = 'gradleTest'
}

archive_war {
  baseName = 'gradleTest'
}

When genaring eclipse projects files using this settings almost everything
works. The only thing missing is that the other sub projects (holding
utilities) are unchecked in the "Java EE Module Dependencies" settings
section of the project. This is needed for eclipse to be able to build and
deploy the project to a test tomcat instance in the same way as gradle
composes its WAR file.

I figured out that the projectDependencies property (setProjectDependencies
and getProjectDependencies) controls wether this is done but i could not
figure out how to construct instances of DefaultProjectDependencies and not
sure if i need to do this anyway. The solution turned out to be changing the
eclipseWtp settings to the following:

eclipseWtp {
  deployName = 'gradleTest'
  projectDependencies = projectDependencies
}

The magic is calling the setter with the results of the getter. This works
because the source reads as follows (javadocs removed):

    public List<DefaultProjectDependency> getProjectDependencies() {
        return (List<DefaultProjectDependency>)
conv(projectDependencies, "projectDependencies");
    }

    public void setProjectDependencies(List<DefaultProjectDependency>
projectDependencies) {
        this.projectDependencies = projectDependencies;
    }


To a java programmer and being new with groovy/gradle i am very surprised to
see the setter operate on a local var while the getter operate on the
convinience object. Is this correct behavior?

Whats even more weird is the fact that the addDependsOnProjects method
operated on the getter. Does the getter need to be called at least once for
the convinience object to initialize? Is the getter operating in a different
scope when running in the build script as opposed to when the task actually
executes? (config vs. runtime)

Is this solution even valid for the problem?

(Please forgive my ignorance of groovy/gradle logic and conventions and the
lengthy post)

Reply via email to