我一直在尝试在 IntelliJ IDEA 中创建一个带有 Spock 测试的 Groovy 项目。
以下是我遵循的步骤:
- 创建 Groovy 项目并添加 Maven 支持。
- 添加了 Spock 依赖项和插件。我使用的 POM 与此非常相似:https://github.com/mariuszs/java-spock-test-sample/blob/master/pom.xml https://github.com/mariuszs/java-spock-test-sample/blob/master/pom.xml
- 由于 Groovy 依赖项发生冲突,我从 Module Settings->Libraries 中删除了 Groovy 2.2 库。这使我能够进行测试。
- 我在“src/main”中创建了一个 Groovy 类..但是当我尝试运行它时出现错误:
Groovyc: Cannot compile Groovy files: no Groovy library is defined for module...
我可能错过了一些东西,因为我厌倦了半天尝试不同的配置。
对于完全常规的项目尝试GMavenPlus https://github.com/groovy/GMavenPlus/wiki/Usage
示例项目:https://github.com/mariuszs/groovy-maven-sample https://github.com/mariuszs/groovy-maven-sample
Install GMavenPlus IntelliJ Plugin https://plugins.jetbrains.com/plugin/7442.
IntelliJ dont recognize source directories src/main/groovy
, configure this manually as shown below from Project Settings -> Modules window:.
配置
<project>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.4</version>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.0-groovy-2.4</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)