Today we have released Buildship 1.0.18. This release contains an exciting new feature that enables users to completely configure the Eclipse classpath. For the details check out the section below. This release also fixes several issues reported by the community.
Improved Java project synchronization
Gradle 3.0 provides a complete classpath configuration model. Previously missing information such as the default output location, source folder excludes-includes and classpath containers are now synchronized in Eclipse. Moreover, the classpath file manipulation done in the eclipse.classpath.file.whenMerged
hook is also considered by Buildship.
The following examples demonstrate exactly what and how can you configure a Java project in Buildship:
Default output location
apply plugin: 'java'
apply plugin: 'eclipse'
eclipse {
classpath {
defaultOutputDir = file('target/bin')
}
}
Configured entry in .classpath file
Custom classpath containers
apply plugin: 'java'
apply plugin: 'eclipse'
eclipse {
classpath {
containers 'org.eclipse.pde.core.requiredPlugins'
}
}
Configured entry in .classpath file
Source folder exclude and include patterns
apply plugin: 'java'
sourceSets {
test {
java {
exclude '**/*.groovy'
include '**/*Test*'
}
}
}
Configured entry in .classpath file
Source folder output location
apply plugin: 'java'
apply plugin: 'eclipse'
eclipse {
classpath {
file {
whenMerged {
def src = entries.find { it.path == 'src/main/java' }
src.output = "/$eclipse.project.name/classes/main-java"
}
}
}
}
[details=Configured entry in .classpath file]
[/details]
Java runtime
The java runtime name configured in the build is used in Eclipse. If thatâs not sufficient, the whole path can be set in the eclipse.classpath.file.whenMerged
block.
apply plugin: 'java'
apply plugin: 'eclipse'
eclipse {
jdt {
javaRuntimeName = 'Domino'
}
}
Configured entry in .classpath file
apply plugin: 'java'
apply plugin: 'eclipse'
eclipse {
classpath {
file {
whenMerged {
def jre = entries.find { it.path.contains 'org.eclipse.jdt.launching.JRE_CONTAINER' }
jre.path = 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/Java SE 8 [1.8.0_65]'
}
}
}
}
Configured entry in .classpath file
Classpath attributes
Classpath attributes can be set on all classpath entries by modifying the AbstractClasspathEntry.entryAttributes
map. This example demonstrates how to configure a source folder to ignore compiler warnings.
apply plugin: 'java'
apply plugin: 'eclipse'
eclipse {
classpath {
file {
whenMerged {
def source = entries.find { it.path == 'src/main/java' }
source.entryAttributes['ignore_optional_problems'] = 'true'
}
}
}
}
[details=Configured entry in .classpath file]
[/details]
Access rules
Access rules can be set on every classpath attributes by modifying the AbstractClasspathEntry.accessRules
list. The access rule types are defined in the org.eclipse.jdt.core.IAccessRule
class.
import org.gradle.plugins.ide.eclipse.model.AccessRule
apply plugin: 'java'
apply plugin: 'eclipse'
eclipse {
classpath {
file {
whenMerged {
def jre = entries.find { it.path.contains 'org.eclipse.jdt.launching.JRE_CONTAINER' }
jre.accessRules.add(new AccessRule('1', 'com/**'))
jre.accessRules.add(new AccessRule('1', 'sun/**'))
}
}
}
}
[details=Configured entry in .classpath file]
[/details]
Library, source and javadoc location
The Classpath.fileReference(Object)
method was added to the public API to be able to set custom source and javadoc location for a classpath entry.
import org.gradle.plugins.ide.eclipse.model.Library
apply plugin: 'java'
apply plugin: 'eclipse'
eclipse {
classpath {
file {
whenMerged {
def lib = entries.find { it.path.contains 'my-commercial-lib.jar' }
lib.javadocPath = fileReference(file('libs/my-commercial-lib-javadoc.jar'))
lib.sourcePath = fileReference(file('libs/m-commercial-lib-source.jar'))
}
}
}
}
[details=Configured entry in classpath container]
[/details]
Declare resources as a library
It can be beneficial to declare resource folders as a library dependencies because this way the contents wonât be copied to the project output location.
import org.gradle.plugins.ide.eclipse.model.Library
apply plugin: 'java'
apply plugin: 'eclipse'
eclipse {
classpath {
file {
whenMerged {
entries.removeAll { it.path == 'src/main/resources' }
entries += new Library(fileReference(file('src/main/resources')))
}
}
}
}
[details=Configured entry in classpath container]
[/details]
Installation
Buildship 1.0.18 is available at the Eclipse Marketplace or at the eclipse.org update sites. Users with Buildship already installed can automatically update to the latest version.