Here’s my build.gradle file (I’ve rearranged the default project file structure provided by the java plugin):
apply plugin: 'war'
apply plugin: 'eclipse'
group = 'someGroup'
version = '0.0.1-SNAPSHOT'
description = "glassfish-hello1"
/*
* JVM version
*/
sourceCompatibility = 1.7
targetCompatibility = 1.7
repositories {
maven { url "http://maven.repository.redhat.com/earlyaccess/all/" }
maven { url "http://maven.repository.redhat.com/techpreview/all" }
maven { url "http://repo.maven.apache.org/maven2" }
}
/*
* Override the default java plugin project structure
* so that it conforms to the JBoss file structure
*/
buildDir = 'target'
sourceSets {
// the compiled java classes of this set will be put in target/classes
main {
output.classesDir = 'target/classes'
output.resourcesDir = 'target/classes'
}
test {
output.classesDir = 'target/test-classes'
output.resourcesDir = 'target/test-classes'
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version:'4.11'
testCompile group: 'org.jboss.arquillian.junit', name: 'arquillian-junit-container', version:'1.1.0.Final'
testCompile group: 'org.jboss.arquillian.protocol', name: 'arquillian-protocol-servlet', version:'1.1.0.Final'
//providedCompile configuration comes from the war plugin, such dependencies will not be included in the war file
providedCompile(group: 'javax.enterprise', name: 'cdi-api', version:'1.0-SP4') {
exclude(module: 'jboss-interceptor-api')
exclude(module: 'jsr250-api')
}
providedCompile group: 'org.jboss.spec.javax.annotation', name: 'jboss-annotations-api_1.1_spec', version:'1.0.1.Final'
providedCompile group: 'org.jboss.spec.javax.ws.rs', name: 'jboss-jaxrs-api_1.1_spec', version:'1.0.1.Final'
providedCompile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.0-api', version:'1.0.1.Final'
providedCompile group: 'org.jboss.spec.javax.ejb', name: 'jboss-ejb-api_3.1_spec', version:'1.0.2.Final'
providedCompile(group: 'org.hibernate', name: 'hibernate-validator', version:'4.2.0.Final') {
exclude(module: 'slf4j-api')
}
providedCompile group: 'org.jboss.spec.javax.faces', name: 'jboss-jsf-api_2.1_spec', version:'2.0.9.Final'
providedCompile group: 'org.hibernate', name: 'hibernate-jpamodelgen', version:'1.2.0.Final'
providedCompile group: 'org.hibernate', name: 'hibernate-validator-annotation-processor', version:'4.2.0.Final'
}
/*
* Override the default java plugin project structure
* so that it conforms to the JBoss file structure
*/
eclipse {
classpath {
defaultOutputDir file('target/classes')
containers = ['org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6']
}
project {
buildCommand 'org.eclipse.wst.jsdt.core.javascriptValidator'
buildCommand 'org.eclipse.wst.common.project.facet.core.builder'
buildCommand 'org.eclipse.m2e.core.maven2Builder'
buildCommand 'org.jboss.tools.jst.web.kb.kbbuilder'
buildCommand 'org.hibernate.eclipse.console.hibernateBuilder'
buildCommand 'org.jboss.tools.cdi.core.cdibuilder'
buildCommand 'org.jboss.tools.ws.jaxrs.metamodelBuilder'
buildCommand 'org.eclipse.wst.validation.validationbuilder'
natures 'org.springsource.ide.eclipse.gradle.core.nature',
'org.eclipse.jem.workbench.JavaEMFNature',
'org.eclipse.wst.common.modulecore.ModuleCoreNature',
'org.eclipse.wst.common.project.facet.core.nature',
'org.hibernate.eclipse.console.hibernateNature',
'org.jboss.tools.jst.web.kb.kbnature',
'org.jboss.tools.cdi.core.cdinature',
'org.jboss.tools.ws.jaxrs.nature',
'org.jboss.tools.jsf.jsfnature',
'org.eclipse.wst.jsdt.core.jsNature'
}
}
If I haven’t executed a gradle task that compiles the test classes and puts them in “target\test-classes” (such as compileTestJava), when, in Eclipse, I click on the project with the right mouse button then “Run As” -> “JUnit Test”, a get a Class not Found Exception. If the .class files are available, then there are no problems.
So each time I create a new test class or make changes to an existing one, I have to run a gradle task before I can run the tests from Eclipse. Isn’t there a way to tell Eclipse to recompile the files automatically?
I’m using the STS plugin for Eclipse, and my Gradle version is 1.9.