首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Groovy和Maven:在编译和测试一个非常简单的

Groovy和Maven:在编译和测试一个非常简单的
EN

Stack Overflow用户
提问于 2020-06-03 15:57:14
回答 1查看 436关注 0票数 1

我被困在试图编译和测试一个非常简单的项目。这是一个初学者的项目,以了解所有这一切如何工作,我目前是塞。

我的主要目标是了解如何处理位于标准文件夹结构之外的资源文件。

我有一个主课,有两种方法。一个加载位于标准文件夹结构(src\main\resources)上的资源文件。另一个加载位于标准结构(resources)之外的自定义文件夹中的资源。

有一个junit文件可以简单地验证资源是否被正确加载。

它在IntelliJ中运行得很好。我只是将资源文件夹声明为资源文件夹,仅此而已。

现在和maven ..。实际上,我甚至不能用gmaven+进行编译。也不做测试。因此,我甚至没有将自定义文件夹声明为pom.xml文件中的资源。

我的pom.xml文件是基于我们在工作中已有的pom,以及我在网上读到的内容。我没办法让它起作用。

这是一个链接到一个7zip文件与我的项目,如果一个人可以让我在正确的轨道上,我将不胜感激。

https://www.dropbox.com/s/jvn32ll5xfvjfwd/GroovyExample.7z?dl=0

这是pom:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         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>groupId</groupId>
    <artifactId>Example</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>

        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>2.4.13</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.4.0</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.gmavenplus</groupId>
                <artifactId>gmavenplus-plugin</artifactId>
                <version>1.8.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>compileTests</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>
                                    <directory>src/main/groovy</directory>
                                    <includes>
                                        <include>**/*.groovy</include>
                                    </includes>
                                </source>
                            </sources>
                            <testSources>
                                <testSource>
                                    <directory>src/test/groovy</directory>
                                    <includes>
                                        <include>**/*.groovy</include>
                                    </includes>
                                </testSource>
                            </testSources>
                        </configuration>
                    </execution>

                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M1</version>
                <configuration>
                    <failIfNoTests>true</failIfNoTests>
                    <testSourceDirectory>str/test/</testSourceDirectory>
                    <includes>
                        <include>**/*Test*.*</include>
                    </includes>
                </configuration>
            </plugin>

        </plugins>
    </build>
</project>

这是输出:

无法从InvokerHelper或GroovySystem获得Groovy版本,只能尝试jar名称。

在项目示例中未能执行目标org.codehaus.gmavenplus:gmavenplus-plugin:1.8.1:compile (默认):目标org.codehaus.gmavenplus:gmavenplus-plugin:1.8.1:compile的执行默认失败。

EN

回答 1

Stack Overflow用户

发布于 2020-07-25 20:32:26

2.4 groovy-all POMs不将Groovy作为依赖项包括在内,因为它们是uber-jar的POM,而不是描述所有Groovy模块jar的POM。因此,GMavenPlus无法找到用于编译的Groovy。<type>pom</type>适用于Groovy2.5和3.0,但不适用于2.4。因此,对于用例,只需删除<type>pom</type> (或将其替换为默认的<type>jar</type>)。这是Groovy通常在2.5之前包含的方式,因此添加了groovy-所有2.5和3.0的POMs以简化转换。见https://groovy-lang.org/releasenotes/groovy-2.5.html#Groovy2.5releasenotes-Packaging

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62177256

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档