简体   繁体   English

从 Intellij 编译项目时,在 Maven 项目上获得“没有为模块定义 groovy 库”

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

Below is the pom.xml content.下面是 pom.xml 的内容。 I generated the project with maven archetype quickstart with junit.我使用 junit 生成了带有 Maven 原型快速入门的项目。 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.当尝试从 Intellij 运行测试时,我得到“没有定义 Groovy 库”,尽管我在这个项目中与 Groovy 无关。

  2. When doing mvn test from command line, no tests are identified.从命令行执行 mvn test 时,未识别任何测试。

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.顺便提一下,我的mac默认java版本是8,所以运行mvn时我把JAVA_HOME导出到12,可能是nr.1的问题,不确定。

    <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.当尝试从 Intellij 运行测试时,我得到“没有定义 Groovy 库”,尽管我在这个项目中与 Groovy 无关。

This sound like a bug, since both pcollections and junit are not related to groovy:这听起来像是一个错误,因为 pcollections 和 junit 都与 groovy 无关:

Try to re-import your project (maven tab + reimport).尝试重新导入您的项目(Maven 选项卡 + 重新导入)。 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.如果这没有帮助,请关闭项目,然后再次打开pom.xml它将提供重新创建项目并丢弃旧数据,同意这一点,它将重建所有内容。

When doing mvn test from command line, no tests are identified.从命令行执行 mvn test 时,未识别任何测试。

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).您开发的测试可能不遵循类解析的surefire约定(它应该以*Test结尾,但如果我没记错的话,它在最新版本的surefire中略有变化,所以现在*Tests也可以)。 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).请在运行“测试”阶段以及您的测试定义之一(即使使用简单的测试代码)时添加 maven 命令行输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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