after upgrade to gradle 4.x - unable to resolve warning for JEE project

697 Views Asked by At

I'm unable to get rid of a warning in a gradle 4.2 build:

Gradle now uses separate output directories for each JVM language, but this build assumes a single directory for all classes from a source set. This behaviour has been deprecated and is scheduled to be removed in Gradle 5.0
    at build_d02ctf5wwx94ec3duxv44z2cn$_run_closure3$_closure6.doCall(...\build.gradle:56)

The projects build EJB jars and therefore the beans.xml file has to end up in the classes output folder. The recommended fix I found was to replace the line mentioned in the warning from:

sourceSets {
  main {
    output.resourcesDir = java.outputDir
  }
  test {
    output.resourcesDir = java.outputDir
  }
}

to:

sourceSets {
  main {
    output.resourcesDir = new File(buildDir, "classes/java/main")
  }
  test {
    output.resourcesDir = new File(buildDir, "classes/java/main")
  }
}

This resolves the warning and the beans.xml is where it needs to be. The issue I cannot figure out is there is another project in the build that depends on the ejb project and runs tests. Using the second approach it does not seem to recognize the beans.xml files (the weld injection in the tests dont work)

project structure:

build.gradle
/ejb-project (builds ejb's and copies beans.xml)
/it-test-project (uses Services from ejb)
/st-test-project
/war-project
/ear-project

The it-test-project contains a project() dependency and this sourceSets:

dependencies {    
  testCompile project(':ejb-project')
  testRuntime project(':ejb-project')
}

sourceSets {
  test {
    // output.resourcesDir = new File(buildDir, "classes/java/main")
    output.resourcesDir = output.classesDir
  }
}

I don't understand how the injection in the test works in the variant above, but once I switch to the commented one does not. I assume it has to do with file references and the dependencies but I don't understand what would be the correct option here.

Any suggestions would be great :)

1

There are 1 best solutions below

0
On BEST ANSWER

So. After some digging I could get rid of the warning message by doing two things:

  1. open my eyes: the test failed because of a missing beans.xml file which is not located in java/main but in in the test folders. Therefore the commented line above does not work, the beans.xml is not there. So make sure you reference the correct folders was actually my resolution.

  2. adding / changing the resourcesDir to the test folder.

This snippet does not lead to a warning:

sourceSets {
    test {
         output.resourcesDir = new File(buildDir, "classes/java/test")
    }
}

Not sure if that is the best way to do this, since this implies the java source set folders. It would be nice to reference them properly somehow - but since I know its 'java' - well I can live with this solution.