generated test-sources folder recognized as sources folder
Hi there,
I am using IntelliJ 2019.1 Ultimate and trying to achieve the following:
I have a jar containing a swagger specification and I want to build a REST client for my project using the swagger maven plugin. This works already and I configured it that it will create the following directory structure:
/target/generated-sources/swagger/src/main/java and /target/generated-sources/swagger/src/test/java so it conforms to the standard maven layout.
Moreover, I configured maven to pick up the test sources directory as test-source directory:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/swagger/src/test/java</source>
</sources>
</configuration>
</execution>
When I run maven on the command line, everything looks fine:
[INFO] --- swagger-codegen-maven-plugin:2.4.4:generate (default) @ myproject ---
[...][INFO] writing file T:\Repositories\myproject\target\generated-sources\swagger\src\test\java\de\xyz\myotherproject\rest\api\DefaultApiTest.java
[...][INFO] --- build-helper-maven-plugin:3.0.0:add-test-source (add-test-source) @ myproject ---
[INFO] Test Source directory: T:\Repositories\myproject\target\generated-sources\swagger\src\test\java added.
[...]
When I use that project in IntelliJ, the IDE picks up that path as "generated sources root" (and not test-sources) so it flags the class red, since the JUnit dependency has scope test and none of the annotations work. When I manually flag that directory as test-sources root it turns green and the errors vanish. But I don't want to do this every time and tell all my fellow-developers to do that. Instead I want IntelliJ to respect that maven configuration.
There seems to be some magic involved here as the /target/generated-sources/swagger/src/main/java is being recognized as source folder no matter whether I ask maven to add it as source folder or not.
Does anyone have an idea on this one?
Thanks!
Harald.
Please sign in to leave a comment.
Works fine for me:
Might be related to some other Maven plugins you use in project for source code generation, like in case described here: https://youtrack.jetbrains.com/issue/IDEA-159954 Can you provide a sample project where issue is reproducible?
Good description of the issue. I have the exact same problem.
@Marten Richert please provide a sample project in YouTrack reported issue at https://youtrack.jetbrains.com/issues/IDEA
@Andrey Dernov I have sample project at hand right now. Which youtrack-issue do you mean? I am not the original reporter in this thread.
A new one: https://youtrack.jetbrains.com/newIssue?draftId=25-2370740 Thanks!
Here you go: https://youtrack.jetbrains.com/issue/IDEA-214950
I faced the same situation.
Nevertheless, IntelliJ :
IntelliJ limitations: