Application Plugin "run" task should first consolidate classes and resources folder or depend on installApp, or stuff like weld-se wont work

I’m currently trying to set up a project using weld-se to build with Gradle using the application plugin. When I execute installApp, everything works fine. When I execute run, weld-se throws an error because it cannot find the beans.

The problem is the following:

project layout: src/main/java/<code here> src/main/resources/META-INF/beans.xml

run execution: - compileJava compiles src/main/java/<code here> to build/classes/main/<classes here> - processResources copies src/main/resources/META-INF/beans.xml to build/resources/main/META-INF/beans.xml - run uses build/classes/main/ and build/resources/main/ as classpath entries - weld-se scans classpath entries that have a META-INF/beans.xml file for beans, so only build/resources/main/ is scanned for beans while the beans of course are in build/classes/main/ and thus the whole thing is broken

installApp execution: - jar packages output of compileJava and processResources together in one JAR file - the generated start scripts use that JAR file as classpath entry - weld-se scans classpath entries that have a META-INF/beans.xml file for beans, so the JAR is scanned, the beans are found and everything is well

This means that using run yields a different execution environment than what is used during production usage and that is bad. I’d say if there is a reason for “run” to use single files in the filesystem instead of a JAR, it should consolidate the files per source set or similar in one directory and use that. If not, it should maybe depend on the generated JARs, or on the result of installApp or similar.

And finally a workaround that works for me currently, but I’m open for better suggestions:

sourceSets.main.resources {
   exclude 'META-INF/beans.xml'
}
  classes {
   inputs.dir 'src/main/resources/META-INF/beans.xml'
   outputs.dir "$buildDir/classes/main/META-INF/beans.xml"
} << {
   copy {
      from('src/main/resources') { include 'META-INF/beans.xml' }
      into "$buildDir/classes/main/"
   }
}

Also if you need auxiliary files during runtime that you package with applicationDistribution, those files are not available if you use the run task. So maybe the better workaround for me will be to make run depend on installApp and then use all JARs in lib as classpath like this:

task run(type: JavaExec, dependsOn: installApp, overwrite: true) {
   description 'Runs this project as a JVM application'
   group 'application'
   main mainClassName
   classpath fileTree("$installApp.destinationDir/lib")
}

I’ve just hitted this issue, thanks for the workaround.