使用Maven和groovy-eclipse编译器编译Groovy

时间:2014-11-04 13:03:24

标签: java maven groovy

我在编译Groovy脚本时遇到问题。当我开发Groovy脚本时,一切正常,我使用IntelliJ IDEA IDE和groovy命令行实用程序来运行它,使用@Grapes@Grab注释。现在,我需要使用Maven转移到已编译的模型。不幸的是,我无法弄清楚我的pom.xml有什么问题,为什么Groovy编译器抱怨这样:

[ERROR] import org.slf4j.LoggerFactory
[ERROR] ^
[ERROR] The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
[...]
[ERROR] import org.slf4j.LoggerFactory
[ERROR] ^
[ERROR] The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files

这是我目前的pom.xml

<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>

    <parent>
        <groupId>com.xyz</groupId>
        <artifactId>com.xyz.parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <groupId>com.uvw</groupId>
    <artifactId>verifymetrics</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>2.3.7</version>
        </dependency>

        <dependency>
            <groupId>com.xyz</groupId>
            <artifactId>com.xyz.client</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>
            <version>2.3</version>
            <classifier>jdk15</classifier>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.codehaus.groovy.modules.http-builder</groupId>
            <artifactId>http-builder</artifactId>
            <version>0.7.1</version>
        </dependency>

        <dependency>
            <groupId>org.codehaus.gpars</groupId>
            <artifactId>gpars</artifactId>
            <version>1.2.1</version>
        </dependency>

        <dependency>
            <groupId>commons-cli</groupId>
            <artifactId>commons-cli</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>18.0</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.7</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jul-to-slf4j</artifactId>
            <version>1.7.7</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.7.7</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.7</version>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <compilerId>groovy-eclipse-compiler</compilerId>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
                <extensions>true</extensions>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy-eclipse-compiler</artifactId>
                        <version>2.8.0-01</version>
                    </dependency>
                    <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy-eclipse-batch</artifactId>
                        <version>2.3.4-01</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>

1 个答案:

答案 0 :(得分:1)

是否有extensions被定义为真的原因?我有一个使用groovy-eclipse编译器的项目,我按照groovy-eclipse-compiler plugin page上的说明进行操作。请注意,那里没有<extensions>标志。

以下是适用于我的插件配置(使用Groovy 2.2.1):

<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <!-- 2.8.0-01 and later require maven-compiler-plugin 3.1 or higher -->
  <version>3.1</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.8.0-01</version>
    </dependency>
    <!-- for 2.8.0-01 and later you must have an explicit dependency on groovy-eclipse-batch -->
    <dependency>
      <groupId>org.codehaus.groovy</groupId>
      <artifactId>groovy-eclipse-batch</artifactId>
      <version>2.1.8-01</version>
    </dependency>
  </dependencies>
</plugin>