Gradle JEE build uses JDK @Resource class instead of server provided one


(Adam Charlton) #1

Hi, I am writing a Gradle script to build a JEE application which eventually gets deployed to a WebSphere Application Server and during development is added to either Eclipse or IntelliJ.

I’m noticing a problem where the application attempts to use the @Resource annotation with the lookup field (e.g. @Resource(lookup=‘test’)) however during both build and viewing the class in the IDE (project files generated by Gradle) this doesn’t work.

The javax.annotation.Resource class from the Java JDK is being used over the one supplied by the Websphere server or the javaee-api-6.0.4 jar that we are attempting to include.

Is there a way to force the Resource class from either the dependency or server jar to be used over the one that comes from rt.jar in the JDK?

Following is the excerpts I am using to add the WebSphere Application Server libraries to the build so they can be used.

sourceSets {
    main.compileClasspath += configurations.was8
    test.compileClasspath += configurations.was8
    test.runtimeClasspath += configurations.was8
}
  dependencies {
    was8 fileTree(dir: "$WAS_DIR/dev/JavaEE/6.0", include: '**/*.jar')
    was8 fileTree(dir: "$WAS_DIR/plugins", include: '**/*.jar')
    was8 fileTree(dir: "$WAS_DIR/lib", include: '**/*.jar')
    was8 fileTree(dir: "$WAS_DIR/tivoli", include: '**/*.jar')
}

Does anyone know a way to somehow allow the WAS Resource class to be loaded and used over the one from the JDK?

Also please let me know if I can provide any more information