Divergent Spock test runner behaviour with multi-module Maven

Answered

This one is a bit odd, as I feel like it's come from nowhere.

 

I recently had quite a flat Maven project, with Spock 2 (2.0-groovy-3.0), and running tests in IntelliJ worked fine - I could write/edit tests on the fly with no issues.

I've now had to convert the project to multi-module, which involved re-iterating some of the GMavenPlus plugin config (tying `compileTests` to the `test-compile` phase, more specifically) in order to generate the `target/test-classes` directory.

 

If that directory doesn't exist, e.g. after a clean (so there's no `target` at all) IntelliJ claims it can't find the classes required to run them.  

If I reset the branch back to the single-module, flat maven project, it seems like IntelliJ runs groovyc, and it generates the `target` directory by itself, with the compiled `test-classes`.

 

Is this a bug, or am I missing some sort of configuration that gives the IDE a way of figuring this out?

0
14 comments

To add, switching to the multi-module branch, reload the maven tab, doing a clean, then running all tests on one submodule's "src/main/java" directory shows that groovyC etc. is running, and it produces a "target" directory, but "test-classes" doesn't include any of the groovy tests.

This is the same behaviour that the gmavenplus plugin showed prior to config.  The POM has the same setup otherwise, with surefire being fully away of the test directory

0

Hi Chris,

Would it be possible for you to share this project, or make a smaller one out of it for demonstration purposes and share that?

0

Hi Arina,

Unfortunately it is confidential work, so I'm unable to.

 

What I can confirm is that running "build" was also failing with multiple "java: package .... does not exist" errors.

I created a new project from scratch, using the same repo, and none of the above errors can be replicated.

 

The build log, for the project where this occurs, had "backward reference index deleted" errors, which I believe has been previously brought up and thought to have been fixed in https://youtrack.jetbrains.com/issue/IDEA-266598.

These only occur on the project when the issue occurs (not when a new one is created), so it seems like an IntelliJ-specific issue with caching or an .idea file.  (I tried invaliding cache prior to creating this topic, and it didn't help)

 

I'm on 2021.3.1, for reference.  Build #IU-213.6461.79

0

> IntelliJ claims it can't find the classes required to run them.  

Which classes can not it find? Where are they expected to be?

>If I reset the branch back to the single-module, flat maven project, it seems like IntelliJ runs groovyc, and it generates the `target` directory by itself, with the compiled `test-classes`.

It could be that IDE does not detect that groovyc needs to be used in project. How do you configure it? Does it help to swith to Eclipse-groovy compiler in the Settings (Preferences on macOS) | Build, Execution, Deployment | Compiler | Java Compiler | Use compiler?

0

> Which classes can not it find? Where are they expected to be?

The test classes.  In 'target/test-classes'.  This was literally in the sentence above it.

> It could be that IDE does not detect that groovyc needs to be used in project. How do you configure it? Does it help to swith to Eclipse-groovy compiler in the Settings (Preferences on macOS) | Build, Execution, Deployment | Compiler | Java Compiler | Use compiler?

 

This is not the case.  As detailed, the issue only appears to happen as a result of some sort of unresolvable configuration in the .idea directory.

When the problem occurs, groovyc is seen as running, but it fails silently (from what I assume to be 'no test resources added for compilation'.

If any of that were the issue, it wouldn't explain how skipping back to a previous commit would fix things, nor checking out the project as new.  The '.idea' folder is not part of the version control and is in .gitignore.

 

If it helps, I can reassure you that I'd post this on stackoverflow or similar if it was an RTFM or non-IDE related issue.  It appears to be a continuation of the issue seen in IDEA-266598

0

>The test classes.  In 'target/test-classes'.  This was literally in the sentence above it.

Please show the exact error you are getting. It seems strange why it needs classes from the target directory? It must look for classes in the sources directories or in the module's dependencies.

>As detailed, the issue only appears to happen as a result of some sort of unresolvable configuration in the .idea directory.

What do you mean by the unresolvable configuration?

0

Please show the exact error you are getting. It seems strange why it needs classes from the target directory? It must look for classes in the sources directories or in the module's dependencies.

This is specifically about running tests, as per the title. Please don't get involved in the ticket if you don't know what Spock is, or even how the underlying JUnit/Maven works (not least with IntelliJ). 

What do you mean by the unresolvable configuration?

The common denominator here is the ".idea" directory.  This, from my understanding, stores project configuration.  If the issue is only solved by regenerating/removing this directory, that translates to "unresolvable configuration" to me.
 
 
 
I'm providing bug feedback here, so even beyond the fact that I pay to use IntelliJ, so as you can imagine it's getting quite annoying to have to explain to you the fundamentals.  It isn't any use whatsoever to the issue at hand.  I'd go as far as to say it's rather the opposite.
0

I'm really for for the inconveniences and the issue you have. But to better understand the problem I need to at least understand the exact error you are getting. I red though the conversation but still it is not clear to me the exact setup. you have. Understanding at least this will help to move forward with the investigation. Thank you for understanding. Can you show a screencast?

0

Right.

When you use a build tool (Maven or Gradle), the classes first need to be compiled.  By running the tests in IntelliJ, it mimics this process and outputs the compiled classes in (default example) the target/test-classes directory (Maven) or build/classes/java/test (Gradle).  It is, to my knowledge, the same process that occurs when you click 'build' in IntelliJ.  I wasn't expected to be the one with the referenceable knowledge on that, though.

No compiled classes? no tests.   Therefore, the "exact error" shown in IntelliJ is "No tests were found", with the console output showing "Class not found: ...."

 

In parallel to this, Java classes were failing to "build" because during that background "build" process, the compiler was reporting that almost every imported package or class did not exist. 

 

The reason why this is happening appears to have been 100% down to IntelliJ, as running the appropriate Maven commands on the command line (e.g. mvn clean test) worked fine.   Why IntelliJ seemed to get in an unrecoverable state of broken compilation processes I do not know, but the issue does not exist on a 'fresh' project - so it is not the project itself, nor my own settings.  I do know, however, that others have had this issue before - as per the linked ticket IDEA-266598 - but it appears that was either closed off prematurely, or incorrectly assumed to be fixed.

0

Thanks. From your the description I had the understanding that you are getting compilation error b.c the class does not exist.

>No compiled classes? no tests.   Therefore, the "exact error" shown in IntelliJ is "No tests were found", with the console output showing "Class not found: ...."

When IDE builds project it takes the classes from the directories which are marked as source roots, compiles them and puts them into the module output directory. For the resources directories - it just copies the content to the module's output directory

>In parallel to this, Java classes were failing to "build" because during that background "build" process, the compiler was reporting that almost every imported package or class did not exist. 

It is hard to tell the reason without known the project structure, what exact classes are not found (are they libraries, or classes from same project or module), in which classes this happens. Can you provide this information?

The https://youtrack.jetbrains.com/issue/IDEA-266598 issue was caused by not related problem and has been fixed in scope of https://youtrack.jetbrains.com/issue/IDEA-265327

>the appropriate Maven commands on the command line (e.g. mvn clean test) worked fine

Try deleting the .idea project configuration and re-import the project afresh into IDE.

0

It is hard to tell the reason without known the project structure, what exact classes are not found (are they libraries, or classes from same project or module), in which classes this happens. Can you provide this information?

I have already done this.

When running build in the IDE, it will fail stating that any/all imported (dependency) classes are not found. 
If mvn compile is ran outside of IntelliJ, on the same project, it has no such issue.

When running tests in the IDE, it will fail because it cannot find any tests.  This is because it is failing to compile and output any tests.  It copies over test resources, but does not compile classes.

 

 

Try deleting the .idea project configuration and re-import the project afresh into IDE.

At which point, you will lose all local history, run configurations etc.

I know this would work, as I've already explained that.

 

Do I take it that you're not actually interested in this bug?  You seem to be more interested in finding a way to convince me that it doesn't exist, despite explaining it from several angles.

0

>Do I take it that you're not actually interested in this bug?  You seem to be more interested in finding a way to convince me that it doesn't exist, despite explaining it from several angles.

Having only textual description without any images/ a sample project it is extremely hard to tell what the issue could be. I can be guessing only, sorry.

>At which point, you will lose all local history, run configurations etc.

If no caches are validated the local history should remain. The run configurations can be saved in external files and then copied back.

0

I think you're severely missing the point, here.

You're describing a workaround, not a fix.  I have a workaround, which I described in the third reply before you started replying - but there's clearly a bug here.  That is what I'm reporting.

 

Are you interested in bugs? Or are you suggesting that it is "normal" behaviour for IntelliJ to have to basically delete a project and start again?

0

I was trying to help you to get the project working on a shape that you wanted (multi-module project).

I'm interested in bugs, this is why I asked you to provide the information that I could use to try to reproduce this. I would very much kindly ask you to be productive in the conversation and provide the information that was requested. Thank you.

0

Please sign in to leave a comment.