IDEA Groovy Test Class Already Exists

IDEA gives my groovy class a warning class MyClassTest already exists in "my.class.package". Also, it seems like not a good job of updating the class when running the test. I will add a statement guaranteed by failure or success, and it will not recognize it later (later it seems arbitrary so far). Given that I'm sure the maven tests pass and work correctly, I suspect this is just an IDEA configuration problem.

here my pom.xml

 <?xml version="1.0" encoding="UTF-8"?> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.xenoterracide</groupId> <artifactId>rpf</artifactId> <version>0.1.0</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.1.9.RELEASE</version> </parent> <build> <plugins> <plugin> <groupId>org.codehaus.gmavenplus</groupId> <artifactId>gmavenplus-plugin</artifactId> <version>1.2</version> <executions> <execution> <goals> <goal>addSources</goal> <goal>addTestSources</goal> <goal>generateStubs</goal> <goal>compile</goal> <goal>testGenerateStubs</goal> <goal>testCompile</goal> <goal>removeStubs</goal> <goal>removeTestStubs</goal> </goals> </execution> </executions> <configuration> <testSources> <testSource> <directory>${project.basedir}/src/test/groovy</directory> <includes> <include>**/*.groovy</include> </includes> </testSource> </testSources> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-rest</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-jpa</artifactId> <version>1.8.0.DATAJPA-622-SNAPSHOT</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> </dependency> <!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> --> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <version>9.3-1102-jdbc41</version> </dependency> <dependency> <groupId>javax.enterprise</groupId> <artifactId>cdi-api</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-all</artifactId> <version>2.3.7</version> <scope>test</scope> </dependency> </dependencies> <properties> <!-- use UTF-8 for everything --> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <start-class>com.xenoterracide.rpf.Application</start-class> <java.version>1.8</java.version> </properties> <repositories> <repository> <id>spring-snapshots</id> <name>Spring Snapshots</name> <url>http://repo.spring.io/snapshot</url> <snapshots> <enabled>true</enabled> </snapshots> </repository> <repository> <id>spring-releases</id> <url>http://repo.spring.io/libs-release</url> </repository> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>http://repo.spring.io/milestone</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>spring-releases</id> <url>http://repo.spring.io/libs-release</url> </pluginRepository> </pluginRepositories> </project> 
+5
source share
3 answers

I fixed the problem by marking the target folder of the artifact as Excluded.

I think duplication is caused by stubs generated in target/generated-sources/groovy-stubs . IDEA should be too curious about these files and may add them to the source set.

+10
source

I had the same problem and setting target dir as an exception did not help. I noticed that the directory:

 /target/generated-sources/groovy-stubs/test 

installed as Sources Root in IDEA. I would remove this in the user interface and the error will disappear, but as soon as I rebuild the project, it will return to it again. Very frustrating. So far I have not looked at all the goals of the gmavenplus plugin.

It turned out that I had too many goals. If you use only groovy for testing, for example, I (with Spock - I do it with JUnit), you should include only the following goals in this plugin:

 addTestSources testGenerateStubs testCompile removeTestStubs 

Remove the rest. After you do this IDEA, everything will be fine with your groovy tests (or Specs in my case). Let me know if this really helped.

+1
source

This is because IntelliJ knows groovy in nature, the only thing you need to do is NOT activate gmaveplus-plugin in IntelliJ:

 <profiles> <profile> <id>groovy-integration</id> <!-- profile to incorporate gmaveplus in normal build --> <activation> <activeByDefault>true</activeByDefault> </activation> <build> <plugins> <plugin> <groupId>org.codehaus.gmavenplus</groupId> <artifactId>gmavenplus-plugin</artifactId> <version>1.5</version> <executions> <execution> <goals> <goal>addSources</goal> <goal>addTestSources</goal> <goal>generateStubs</goal> <goal>compile</goal> <goal>testGenerateStubs</goal> <goal>testCompile</goal> <goal>removeStubs</goal> <goal>removeTestStubs</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> <profile> <id>development-in-idea</id> <!-- suppress `groovy-integration` profile by default in IntelliJ --> <activation> <property> <name>idea.version</name> </property> </activation> </profile> </profiles> 

On the one hand, when you launch the maven target from the IntelliJ IDEA Maven Projects tool window directly, the groovy-integration profile will not be activated as usual.

However, you can always go to the test folder, click "Run" tests in "..." and get all the benefits IntelliJ brings to you.

Eliminating the gmavenplus plugin inside IntelliJ IDEA is another advantage; IntelliJ IDEA sometimes adds generated test stubs as sources instead of test sources and cannot compile them due to the lack of dependencies in the test range.

0
source

Source: https://habr.com/ru/post/1207094/


All Articles