IntelliJ stopped copying resources into target folder when running JUnit tests...

Answered

Hi all,

I'm using a maven project. When I do a clean install with maven, all my tests pass.

When I try to run my unit tests directly without cleaning my target folder first, they pass too.

When I run a clean on my project, and then try to run the unit tests, they fail, because the tests can't find my spring config (applicationContext.xml) file on the classpath.

A look into the target folder revealed it hadn't been copied there.

The JUnit run config is set to Build, Activate tool window before launch.

Preferences > Build, Execution, Deployment > Compiler has a tick on Clear output directory on rebuild (which is why I don't understand that a mvn install followed by running unit tests works).

Project structure > Modules > <my module> > Sources correctly shows the Resources folder set to src/main/resources and the Test Resources folder to src/test/resources (which is why I don't understand why the xml files aren't copied over). The target folder is set as excluded.

The java files do get compiled as expected and copied into target/ when I run the tests after a mvn clean - which is why I don't think it is an output directory issue...

Any idea why this isn't working for me? :)

I'm running 2017.2.2 Ultimate, and execute all maven commands via IntelliJ's maven panel...

20 comments
Comment actions Permalink

I'm pulling it using the Update mechanism as I type...

BTW: Marking an additional folder in the project's root as test resources copied its contents without issues... *sigh*

0
Comment actions Permalink

Same issue in 2017.2.3 EAP, I'm afraid...

0
Comment actions Permalink

Please file a bug at https://youtrack.jetbrains.com/issues/IDEA and attach a sample project to reproduce.

0
Comment actions Permalink

FYI: I just unmarked the test resources and resources folders, and now it works...

0
Comment actions Permalink

Folders should be configured as sources/test sources/resources/test resources automatically based on pom.xml when you import the Maven project. All the changes you make manually in IntelliJ IDEA Project Structure will be discarded on the next Maven project refresh/reimport.

0
Comment actions Permalink

So, reimporting the maven project (it's a child project) marked the folders all right, and the xml files are still being copied. Yay! 

Unfortunately, it (i.e Hibernate) now doesn't seem to find compiled classes from another project at runtime...

Here is the simplified project structure:

root
+-- subA
| +-- subWithIssues
| +-- ...
+-- subB <= holds domain classes that can't be found at runtime.
+-- ...


Reimporting all maven modules didn't fix that one, but at least the resources are being copied...

I have a hunch that I might get that issue to work if I change from Build to Build Project, though...

0
Comment actions Permalink

The renamed Build options in the Run/Debug config aren't properly explained in the help, btw. That only lists Make, not Build and Build Project. 

https://www.jetbrains.com/help/idea/2017.2/run-debug-configuration-junit.html?utm_medium=help_link&utm_source=from_product&utm_campaign=IU&utm_content=2017.2&search=Run%20confi

0
Comment actions Permalink

Here's a ticket for resources located under source folder: https://youtrack.jetbrains.com/issue/IDEA-185076

0
Comment actions Permalink

This issue is happening in the latest IntelliJ, with Maven sub-projects. confirmed w/ JUnit projects.

Consider this structure:

parent-project-ear
+-- module-project
| +-- subWithIssues
| +--pom.xml <= This is POM belonging to sub-project
+-- yet-another-irrelevant-project
+-- ...
+pom.xml <= this is parent POM, which does NOT have referenced "module-project" in it

In this setup, if I go (in command prompt) to "module-project" and execute "mvn test", all is working fine. However, if I click on desired test in IntelliJ, it will compile, but NOT copy over resources.

I confirmed this in a way, if I modify parent POM, and add reference to "module-project", then IntelliJ figures it, and all works fine.

 

0
Comment actions Permalink

Hi. Could you please raise a ticket at https://youtrack.jetbrains.com/issues with project example attached.

0
Comment actions Permalink

I am still seeing this issue, using 2019.1.2.

0
Comment actions Permalink

Please share the reproducible test case project.

0
Comment actions Permalink

Might be hard, but I'll try.  For what it's worth, the symptoms I'm seeing pretty much match https://youtrack.jetbrains.com/issue/IDEA-97454.

0
Comment actions Permalink

I am finding it very hard to distill it down to an isolated project.  There are many moving parts in our projects, so without a deeper understanding of Idea's build system, it is very hard for me to reason about which combinations to try out.  

Our projects are maven projects, with extensive sub-module hierarchies; a lot of submodules generate code and/or use annotation processors.  IntelliJ correctly identifies the various resource directories.

What I have done to try to isolate the behaviour:

* Checked out a clean version of one of my projects, built it from within IDEA, verified that the test resources don't get copied unless I build the project using maven.

* Started a new maven project from scratch, saw that test resources do get copied.  If I delete them manually, they get copied if I choose 'Build->recompile' or 'Build->rebuild project', but not if I run 'Build->Build project'.

* Repeated the previous step with a maven project with sub-modules - same result.

Some guidance from you on how we can isolate the root cause together would be appreciated!

0
Comment actions Permalink

Let's start with the formal bug report at https://youtrack.jetbrains.com/issues/IDEA .

Describe what you are doing and what happens instead. Provide idea.log and build.log with debug info for each specific case that doesn't work as expected, see https://intellij-support.jetbrains.com/hc/articles/207241085 .

If possible, share your pom.xml files and the project files IntelliJ IDEA generates (.idea directory contents and the .iml files).

0
Comment actions Permalink

Hi Serge,

I apologize for not following up again until now, thanks for bearing with me. I finally found the time to do some root cause analysis for the issue, and got to the bottom of it: it turned out that the sub-module where I was having the problems was configured with the wrong packaging in it's pom: packaging was set to 'pom' instead of 'jar'.

We had never noticed this error in the past, as our systems don't depend on delivery of that particular sub-module at all - it contains sample/exploratory code that we typically use standalone in the IDE.  A contributing factor to us never discovering this issue is also the fact that IntelliJ does compile the module while Maven does not.  Apparently, IntelliJ recently stopped copying resource files in this edge-case, but it still happily compiles the classes.  

I don't know if it is worth the effort to fix this inconsistency in IntelliJ's handling of pom-only modules, but I can add a ticket if you'd like me to.

1
Comment actions Permalink

Thanks for the update! I've filled the issue to note this inconsistence: https://youtrack.jetbrains.com/issue/IDEA-221071 Feel free to vote and provide your feedback.

0
Comment actions Permalink

Thanks Andrey.  I can't see the issue however - is it only visible internally or something?

0
Comment actions Permalink

Sorry, corrected the visibility.

0

Please sign in to leave a comment.