来自mvn archetype的GMaven项目:generate不是`mvn compile`

时间:2012-03-28 15:38:16

标签: maven groovy gmaven-plugin

我用:

生成了一个空项目

mvn archetype:generate -DarchetypeGroupId=org.codehaus.gmaven.archetypes -DarchetypeArtifactId=gmaven-archetype-basic -DarchetypeVersion=1.4

并且mvn compile无法使用一堆邮件"package groovy.lang does not exist"

(对于archetypeVersion我刚刚选择了最后一个GMaven版本)

我的Maven / GMaven / Groovy出了什么问题?

<?xml version="1.0" encoding="UTF-8"?>
<!--
    Generated from archetype; please customize.
-->

<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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>a</groupId>
    <artifactId>asd</artifactId>
    <name>asd project</name>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.gmaven</groupId>
                <artifactId>gmaven-plugin</artifactId>
                <version>1.4</version>
                <configuration>
                    <providerSelection>1.8</providerSelection>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>generateStubs</goal>
                            <goal>compile</goal>
                            <goal>generateTestStubs</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

2 个答案:

答案 0 :(得分:2)

我为Groovy in Maven做了一个完整的例子。看看吧。

答案 1 :(得分:1)

让它以我自己的方式工作 - 这是一个版本的问题。 @khmarbaise 的版本有一些好主意,比如版本灵活性。

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <groovy.version>2.0.0-beta-2</groovy.version>
</properties>

<dependencies>

    <!-- ... something ... -->

    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy</artifactId>
        <version>${groovy.version}</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.gmaven.runtime</groupId>
        <artifactId>gmaven-runtime-1.7</artifactId>
        <version>1.3</version>
        <exclusions>
            <exclusion>
                <groupId>org.codehaus.groovy</groupId>
                <artifactId>groovy-all</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

<!-- ... something ... -->

<build>
    <!-- make Java compile from groovy folders as well... -->
    <sourceDirectory>src/main/groovy</sourceDirectory>
    <testSourceDirectory>src/test/groovy</testSourceDirectory>

<plugins>
    <plugin>
        <groupId>org.codehaus.gmaven</groupId>
        <artifactId>gmaven-plugin</artifactId>
        <version>1.3</version>
        <dependencies>
            <dependency>
                <groupId>org.codehaus.groovy</groupId>
                <artifactId>groovy</artifactId>
                <version>${groovy.version}</version>
            </dependency>
            <dependency>
                <groupId>org.codehaus.gmaven.runtime</groupId>
                <artifactId>gmaven-runtime-1.7</artifactId>
                <version>1.3</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
        </dependencies>
        <executions>
            <execution>
                <configuration>
                    <providerSelection>1.7</providerSelection>
                </configuration>
                <goals>
                    <goal>generateStubs</goal>
                    <goal>compile</goal>
                    <goal>generateTestStubs</goal>
                    <goal>testCompile</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
            <source>1.5</source>
            <target>1.5</target>
        </configuration>
    </plugin>
</plugins>