Running Weld CDI under IDEA and beans.xml placement
I build a project using IDEA 2017.2.5. The resulting classes are put under out/production/classes/ and the resources are put under out/production/resources/. Both directories are in the classpath when running the application. The problem is with CDI beans discovery, which assumes that META-INF/beans.xml is under the same directory as classes, not just in the classpath. Specifically Weld does the following:
1. Find META-INF/beans.xml in classpath => out/production/resources/META-INF/beans.xml
2. Go two directories up => out/production/resources/
3. Look for all classes under the resulting directory out/production/resources/ => no classes found
4. Throw infamous WELD-001408
A fix for this is to copy/move META-INF/beans.xml from out/production/resources/ to out/production/classes/. If I do this manually application runs fine from within IDEA. How can I make IDEA do this copy/move automatically?
FYI, to solve a similar problem with gradle (running using "gradlew run") I define:
processResources { destinationDir = sourceSets.main.java.outputDir }
However, IDEA ignores gradle directories and uses its own out/ directory.
Can I specify destination resource directory in gradle in a such a way that IDEA (upon gradle import) will use it?
Please sign in to leave a comment.
Please see https://youtrack.jetbrains.com/issue/IDEA-175172 if you want to modify the output directories used by IntelliJ IDEA for Gradle projects.
Thanks, Serge! This solved my issue.