天天看點

mvn編譯java和groovy引言解決

  • 引言
  • 解決

引言

準備自己編譯Spring-Bean學習學習。 解壓并編譯mvn倉庫裡面的

org/springframework/spring-beans/4.2.5.RELEASE/spring-beans-4.2.5.RELEASE-sources.jar

時出現如下兩種現狀:

  • 解壓時:多個

    GroovyBeanDefinitionWrapper.java

    GroovyBeanDefinitionReader.java

  • 編譯時:報錯找不到

    GroovyDynamicElementReader

解決

Spring Bean 4 以後用上了Groovy。 編譯的時候直接使用Spring 4的pom編譯無法成功。 可以在pom裡面加上編譯插件。 這樣就可以成功了:

<build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.0</version>
                <configuration>
                    <compilerId>groovy-eclipse-compiler</compilerId>
                    <verbose>true</verbose>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy-eclipse-compiler</artifactId>
                        <version>2.9.2-01</version>
                    </dependency>
                    <dependency>
                        <groupId>org.codehaus.plexus</groupId>
                        <artifactId>plexus-compiler-api</artifactId>
                        <version>2.8.1</version>
                    </dependency>
                    <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy-eclipse-batch</artifactId>
                        <version>2.4.3-01</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
           
同時網上查詢有用

gmaven

插件的。 但是實測體驗很差,編譯失敗。

使用如上配置的插件是将編譯任務委托給了

groovy-eclipse-batch

需要注意的事情是, 放置

Groovy

檔案的目錄, 需要同時有java檔案存在, 否則它會被忽略掉。