EclipseProject

API Documentation:EclipseProject

Enables fine-tuning project details (.project file) of the Eclipse plugin

Example of use with a blend of all possible properties. Bear in mind that usually you don't have configure eclipse project directly because Gradle configures it for free!

plugins {
    id 'java'
    id 'eclipse'
}

eclipse {
  project {
    //if you don't like the name Gradle has chosen
    name = 'someBetterName'

    //if you want to specify the Eclipse project's comment
    comment = 'Very interesting top secret project'

    //if you want to append some extra referenced projects in a declarative fashion:
    referencedProjects 'someProject', 'someOtherProject'
    //if you want to assign referenced projects
    referencedProjects = ['someProject'] as Set

    //if you want to append some extra natures in a declarative fashion:
    natures 'some.extra.eclipse.nature', 'some.another.interesting.nature'
    //if you want to assign natures in a groovy fashion:
    natures = ['some.extra.eclipse.nature', 'some.another.interesting.nature']

    //if you want to append some extra build command:
    buildCommand 'buildThisLovelyProject'
    //if you want to append a build command with parameters:
    buildCommand 'buildItWithTheArguments', argumentOne: "I'm first", argumentTwo: "I'm second"

    //if you want to create an extra link in the eclipse project,
    //by location uri:
    linkedResource name: 'someLinkByLocationUri', type: 'someLinkType', locationUri: 'file://someUri'
    //by location:
    linkedResource name: 'someLinkByLocation', type: 'someLinkType', location: '/some/location'

    //if you don't want any node_modules folder to appear in Eclipse, you can filter it out:
    resourceFilter {
      appliesTo = 'FOLDERS'
      type = 'EXCLUDE_ALL'
      matcher {
        id = 'org.eclipse.ui.ide.multiFilter'
        arguments = '1.0-name-matches-false-false-node_modules'
      }
    }
  }
}

For tackling edge cases users can perform advanced configuration on resulting XML file. It is also possible to affect the way eclipse plugin merges the existing configuration via beforeMerged and whenMerged closures.

beforeMerged and whenMerged closures receive Project object

Examples of advanced configuration:

plugins {
    id 'java'
    id 'eclipse'
}

eclipse {
  project {

    file {
      //if you want to mess with the resulting XML in whatever way you fancy
      withXml {
        def node = it.asNode()
        node.appendNode('xml', 'is what I love')
      }

      //closure executed after .project content is loaded from existing file
      //but before gradle build information is merged
      beforeMerged { project ->
        //if you want skip merging natures... (a very abstract example)
        project.natures.clear()
      }

      //closure executed after .project content is loaded from existing file
      //and after gradle build information is merged
      whenMerged { project ->
        //you can tinker with the Project here
      }
    }
  }
}

Properties

PropertyDescription
buildCommands

The build commands.

comment

The comment.

file

See EclipseProject.file(org.gradle.api.Action)

linkedResources

The linked resources.

name

The name.

natures

The natures.

referencedProjects

The referenced projects.

resourceFilters

The resource filters of the eclipse project.

Methods

MethodDescription
buildCommand(buildCommand)

Adds a build command to the eclipse project.

buildCommand(args, buildCommand)

Adds a build command with arguments to the eclipse project.

file(action)

Enables advanced configuration like tinkering with the output XML or affecting the way existing .project content is merged with gradle build information. For example see docs for EclipseProject

linkedResource(args)

Adds a resource link (aka 'source link') to the eclipse project.

natures(natures)

Appends natures entries to the eclipse project.

referencedProjects(referencedProjects)

The referenced projects of this Eclipse project (*not*: java build path project references).

resourceFilter(configureClosure)

Adds a resource filter to the eclipse project.

resourceFilter(configureAction)

Adds a resource filter to the eclipse project.

Script blocks

BlockDescription
file

Enables advanced configuration like tinkering with the output XML or affecting the way existing .project content is merged with gradle build information

Property details

List<BuildCommand> buildCommands

The build commands.

Default with eclipse and java plugins:
Java builder, plus Scala and Web builders as appropriate.

String comment

The comment.

Default with eclipse and java plugins:
project.description

Set<Link> linkedResources

The linked resources.

Default with eclipse and java plugins:
[]

String name

The name.

Default with eclipse and java plugins:
${project.name} (sometimes prefixed with parts of ${project.path} to guarantee uniqueness)

List<String> natures

The natures.

Default with eclipse and java plugins:
Java nature, plus Groovy, Scala and Web natures as appropriate.

Set<String> referencedProjects

The referenced projects.

Default with eclipse and java plugins:
[]

Set<ResourceFilter> resourceFilters (read-only)

The resource filters of the eclipse project.

Default with eclipse and java plugins:
[]

Method details

void buildCommand(String buildCommand)

Adds a build command to the eclipse project.

For example see docs for EclipseProject

void buildCommand(Map<String, String> args, String buildCommand)

Adds a build command with arguments to the eclipse project.

For example see docs for EclipseProject

void file(Action<? super XmlFileContentMerger> action)

Enables advanced configuration like tinkering with the output XML or affecting the way existing .project content is merged with gradle build information. For example see docs for EclipseProject

void linkedResource(Map<String, String> args)

Adds a resource link (aka 'source link') to the eclipse project.

For example see docs for EclipseProject

void natures(String... natures)

Appends natures entries to the eclipse project.

For example see docs for EclipseProject

void referencedProjects(String... referencedProjects)

The referenced projects of this Eclipse project (*not*: java build path project references).

Referencing projects does not mean adding a build path dependencies between them! If you need to configure a build path dependency use Gradle's dependencies section or eclipse.classpath.whenMerged { classpath -> ... to manipulate the classpath entries

ResourceFilter resourceFilter(Closure configureClosure)

Adds a resource filter to the eclipse project.

For examples, see docs for ResourceFilter

ResourceFilter resourceFilter(Action<? super ResourceFilter> configureAction)

Adds a resource filter to the eclipse project.

For examples, see docs for ResourceFilter

Script block details

file { }

Enables advanced configuration like tinkering with the output XML or affecting the way existing .project content is merged with gradle build information

The object passed to whenMerged{} and beforeMerged{} closures is of type Project

For example see docs for EclipseProject

Delegates to:
XmlFileContentMerger from file