3

我正在尝试从头开始一个 Groovy/Java 项目。我创建了一个带有测试的 Groovy 类。

构建时,我收到以下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project repository: Compilation failure
[ERROR] Failure executing groovy-eclipse compiler:
[ERROR] The system cannot find the path specified.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on projec
t repository: Compilation failure
Failure executing groovy-eclipse compiler:
The system cannot find the path specified.

        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
Failure executing groovy-eclipse compiler:
The system cannot find the path specified.

        at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:858)
        at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
        ... 19 more

我已经运行进程监视器来查看它找不到什么路径,并且说如下:

D:\Programmeren\Workspace\BirthdayAppV2\JAVA_HOME\bin\
D:\Programmeren\Workspace\BirthdayAppV2\ GROOVY_HOME\bin\
D:\Programmeren\Workspace\BirthdayAppV2\domain\${env.JAVA_HOME_7}\bin\javac
D:\Programmeren\Workspace\BirthdayAppV2\domain\${env.JAVA_HOME_7}\bin\

看来 maven 没有正确使用我的 JAVA_HOME 变量。

有人有解决这个问题的方法吗?

这是我的主要pom:

<?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>be.vandevelde.glenn</groupId>
<artifactId>BirthdayAppV2</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<name>BirthdayManagerV2</name>

<properties>
    <java.version>1.7</java.version>
    <spring.version>3.2.2</spring.version>
    <groovyVersion>2.1.3</groovyVersion>
</properties>

<modules>
    <module>repository</module>
    <module>domain</module>
</modules>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.spockframework</groupId>
        <artifactId>spock-core</artifactId>
        <version>0.7-groovy-2.0</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>${groovyVersion}</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <compilerId>groovy-eclipse-compiler</compilerId>
                <!-- set verbose to be true if you want lots of uninteresting messages -->
                <!-- <verbose>true</verbose> -->
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-eclipse-compiler</artifactId>
                    <version>2.7.0-01</version>
                </dependency>
                <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-eclipse-batch</artifactId>
                    <version>2.1.3-01</version>
                </dependency>
            </dependencies>
        </plugin>

        <plugin>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-eclipse-compiler</artifactId>
            <version>2.7.0-01</version>
            <extensions>true</extensions>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.5</version>
            <executions>
                <execution>
                    <id>add-source</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>src/main/groovy</source>
                        </sources>
                    </configuration>
                </execution>
                <execution>
                    <id>add-test-source</id>
                    <phase>generate-test-sources</phase>
                    <goals>
                        <goal>add-test-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>src/test/groovy</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
                <showDeprecation>true</showDeprecation>
                <showWarnings>true</showWarnings>
                <executable>${env.JAVA_HOME_7}/bin/javac</executable>
                <fork>true</fork>
            </configuration>
        </plugin>
    </plugins>
</build>

4

1 回答 1

2

您的设置可能存在不止一个问题。首先,您的环境的输出表明环境变量未正确解析(D:\Programmeren\Workspace\BirthdayAppV2\JAVA_HOME\bin\- 这是您的 JDK 的路径吗?)。设置 JAVA_HOME 和 Maven 环境变量记录在各自的项目页面上。你应该从那开始。

之后,我建议您重新构建您的 Maven 配置并仔细阅读Maven Wiki 条目的Groovy-Eclipse-Plug-in并从一个像这样的更简单的配置开始,它编译 Java 7 和 Groovy 文件:

    <?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>your.group</groupId>
        <artifactId>groovy-eclipse-compiler-maven-example</artifactId>
        <version>1-SNAPSHOT</version>
        <name>groovy-eclipse-compiler-maven-example</name>

        <packaging>jar</packaging>

        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.source.encoding>UTF-8</project.source.encoding>

            <java.source.version>1.7</java.source.version>
            <java.target.version>1.7</java.target.version>

            <junit.version>4.10</junit.version>
        </properties>

        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>2.6</version>
                    <configuration>
                        <includeEmptyDirs>true</includeEmptyDirs>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.3.2</version>
                    <configuration>
                        <compilerId>groovy-eclipse-compiler</compilerId>
                        <source>${java.source.version}</source>
                        <target>${java.target.version}</target>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.codehaus.groovy</groupId>
                            <artifactId>groovy-eclipse-compiler</artifactId>
                            <version>2.7.0-01</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>

        <dependencies>
            <dependency>
                <groupId>org.codehaus.groovy</groupId>
                <artifactId>groovy-all</artifactId>
                <version>2.0.4</version>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>${junit.version}</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </project>

重要的是,src/main/javasrc/test/java源目录为空,如文档中所述。(在 Ubuntu 上使用 Maven 3.0.3、JDK 1.7.0.21 测试)

祝你好运!

于 2013-06-07T07:42:06.027 回答