我在src / main / groovy中有一个带有groovy文件的项目,并且这些文件在src / main / java中使用,并且在获取Groovy文件引用时出现错误。我无法在类路径中看到我的Groovy文件。 我的pom.xml具有设置常规源文件夹的代码
<build>
<resources>
<resource>
<targetPath>.</targetPath>
<directory>src/main/groovy</directory>
</resource>
<resource>
<targetPath>.</targetPath>
<directory>src/main/resources</directory>
</resource>
<resource>
<targetPath>.</targetPath>
<directory>src/main/config</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.9.1-01</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.4.3-01</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.9.1-01</version>
<!-- <extensions>true</extensions> -->
</plugin>
<!-- Plugin Management -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.eclipse.jdt.groovy.core.groovyNature</projectnature>
</additionalProjectnatures>
<!-- Source includes is necessary to allow groovy files in the java
folder, else eclipse will throw a filtering exception -->
<sourceIncludes>
<sourceInclude>**/*.groovy</sourceInclude>
</sourceIncludes>
<!-- Download sources will make maven download and attach source files
where available -->
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<compilerVersion>${java-version}</compilerVersion>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.12</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>
</plugins>
请建议进行任何更改以使groovy文件源文件夹进入类路径
答案 0 :(得分:0)
如果您指的是Eclipse项目:Groovy源文件夹是否在Package Explorer中出现在依赖它们的Java之前(又名上方)?
例如,您可能会看到以下内容:
Package Explorer
ProjectName
src/main/java
src/test/java
src/main/groovy
src/test/groovy
Maven Dependencies
JRE System Library
...
pom.xml
使用groovy-eclipse-compiler
适配器的指南在这里:https://github.com/groovy/groovy-eclipse/wiki/Groovy-Eclipse-Maven-plugin这里有一个用于设置额外源文件夹的部分。
此外,您可以在src / * / groovy文件夹中混合使用Groovy和Java源。 groovy编译器适配器将在必要时联合调用Java编译器。