簡體   English   中英

Maven使用gmaven-plugin編譯混合Java + Groovy 1.7項目

[英]Maven compile mixed Java + Groovy 1.7 project, using gmaven-plugin

根據前兩個答案: maven dependencies groovy 我正在嘗試使用來自org.codehaus.gmaven的GMaven-plugin,使用Maven編譯混合Java 6 + Groovy項目。 直到昨天我們使用的是舊的1.6.0版本的Groovy(在我們最終完成它之后從未改變它),但是由於1.7.0現在穩定,我認為我們會改用它。

如果只是那么簡單......我現在遇到的問題似乎有兩個方面:

  • Groovy 1.6在某種程度上仍然被選為默認值。 (如下面的stacktrace中所示)
  • groovy:generateStubs因構建錯誤而停止:意外節點:節點[7:1,64,注釋]

有誰知道如何解決上述兩個問題,或者可以提供一個工作pom來編譯與Maven的Groovy 1.7代碼混合的Java 6代碼?

使用gmaven / groovy.maven / groovy.maven.gmaven編譯舊版本的Groovy時,有很多令人困惑/矛盾/過時的文檔,現在真的沒有幫助。

作為參考,這是我的pom.xml和Maven -e輸出的一部分:

<dependencies>
    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>1.7.0</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.gmaven</groupId>
            <artifactId>gmaven-plugin</artifactId>
            <version>1.2</version>
            <dependencies>
                <dependency>
                    <groupId>org.codehaus.gmaven.runtime</groupId>
                    <artifactId>gmaven-runtime-1.7</artifactId>
                    <version>1.2</version>
                </dependency>
                <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-all</artifactId>
                    <version>1.7.0</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <goals>
                        <goal>generateStubs</goal>
                        <goal>compile</goal>
                        <goal>generateTestStubs</goal>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

堆棧跟蹤:

[INFO] ------------------------------------------------------------------------
[INFO] Building Client
[INFO]    task-segment: [clean, package]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] [groovy:generateStubs {execution: default}]
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Unexpected node: Node[7:1,64,ANNOTATIONS]

[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Unexpected node: Node[7:1,64,ANNOTATIONS]
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
        at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
        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:616)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: Unexpected node: Node[7:1,64,ANNOTATIONS]
        at org.codehaus.gmaven.plugin.MojoSupport.execute(MojoSupport.java:85)
        at org.codehaus.gmaven.plugin.stubgen.AbstractGenerateStubsMojo.execute(AbstractGenerateStubsMojo.java:60)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
        ... 17 more
Caused by: org.codehaus.gmaven.runtime.support.stubgen.UnexpectedNodeException: Unexpected node: Node[7:1,64,ANNOTATIONS]
        at org.codehaus.gmaven.runtime.support.stubgen.parser.NodeSupport.ensure(NodeSupport.java:96)
        at org.codehaus.gmaven.runtime.support.stubgen.model.ModelFactorySupport.identifier(ModelFactorySupport.java:896)
        at org.codehaus.gmaven.runtime.support.stubgen.model.ModelFactorySupport.importDef(ModelFactorySupport.java:185)
        at org.codehaus.gmaven.runtime.support.stubgen.model.ModelFactorySupport.process(ModelFactorySupport.java:122)
        at org.codehaus.gmaven.runtime.support.stubgen.model.ModelFactorySupport.create(ModelFactorySupport.java:90)
        at org.codehaus.gmaven.runtime.support.stubgen.model.ModelFactorySupport.create(ModelFactorySupport.java:61)
        at org.codehaus.gmaven.runtime.v1_6.StubCompilerFeature$StubCompilerImpl.render(StubCompilerFeature.java:101)
        at org.codehaus.gmaven.runtime.v1_6.StubCompilerFeature$StubCompilerImpl.compile(StubCompilerFeature.java:90)
        at org.codehaus.gmaven.plugin.stubgen.AbstractGenerateStubsMojo.compile(AbstractGenerateStubsMojo.java:160)
        at org.codehaus.gmaven.plugin.stubgen.AbstractGenerateStubsMojo.process(AbstractGenerateStubsMojo.java:131)
        at org.codehaus.gmaven.plugin.ComponentMojoSupport.doExecute(ComponentMojoSupport.java:60)
        at org.codehaus.gmaven.plugin.MojoSupport.execute(MojoSupport.java:69)
        ... 20 more

我有同樣的問題。 我錯過了1.7的providerSelection配置設置。

試試這個配置它應該適合你。

  <plugin>
      <groupId>org.codehaus.gmaven</groupId>
      <artifactId>gmaven-plugin</artifactId>
      <version>1.2</version>
      <configuration> 
        <providerSelection>1.7</providerSelection> 
      </configuration> 
      <dependencies>
          <dependency>
            <groupId>org.codehaus.gmaven.runtime</groupId>
            <artifactId>gmaven-runtime-1.7</artifactId>
            <version>1.2</version>
            <exclusions>
              <exclusion>
                <groupId>org.codehaus.groovy</groupId>
                <artifactId>groovy-all</artifactId>
              </exclusion>
            </exclusions>
          </dependency>
          <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>1.7.0</version>
          </dependency>
      </dependencies>
      <executions>
          <execution>
              <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>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
            </configuration>
        </plugin>

也許有辦法讓這個默認?

<plugins>
<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerId>groovy-eclipse-compiler</compilerId>                    
                </configuration>
<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.1.5-03</version>
      </dependency>
</dependencies>             
            </plugin>   </plugins>

看到這篇文章,它幫助我編譯java和groovy

Groovy Java編譯在一起

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM