简体   繁体   中英

Getting "no groovy library is defined for module" on a maven project when compiling the project from Intellij

Below is the pom.xml content. I generated the project with maven archetype quickstart with junit. I encounter two problems:

  1. When trying to run tests from Intellij, I get "no Groovy library defined", although I have nothing to do with Groovy in this project.

  2. When doing mvn test from command line, no tests are identified.

To mention, the default java version is 8 on my mac, so when running mvn i export JAVA_HOME to 12, maybe it's related to the problem nr.1, not sure.

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>12</maven.compiler.source>
        <maven.compiler.target>12</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.pcollections</groupId>
            <artifactId>pcollections</artifactId>
            <version>3.1.3</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

When trying to run tests from Intellij, I get "no Groovy library defined", although I have nothing to do with Groovy in this project.

This sound like a bug, since both pcollections and junit are not related to groovy:

Try to re-import your project (maven tab + reimport). If this doesn't help, close the project, and open up again the pom.xml it will offer to re-create the project and discard old data, agree to this and it will rebuild everything.

When doing mvn test from command line, no tests are identified.

Probably the tests that you've developed do not follow the surefire convention for classes resolution (It should end with *Test although if I remember correctly it has changed slightly in the latest versions of surefire, so now, also *Tests is ok). Please add the maven command line output when it runs the "test" phase as well as one of your test definitions (even with a trivial test code).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM