Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to resolve groovy source in test files #321

Closed
ghost opened this issue Jul 24, 2017 · 13 comments
Closed

Unable to resolve groovy source in test files #321

ghost opened this issue Jul 24, 2017 · 13 comments

Comments

@ghost
Copy link

ghost commented Jul 24, 2017

I am fairly new to Groovy. I have created a groovy project and have converted it to maven. I use Eclipse Kepler with groovy support for development.
When I run the maven build locally, everything works fine, but when I run the build on Jenkins, I see unresolved groovy source file errors and all the compilation errors are only in test cases.
Does anyone know why do I have an issue on Jenkins? Any pointers on this would be vey helpful.
section in my pom.xml file looks like below. Thank you.

<build>
	<sourceDirectory>src/groovy</sourceDirectory>
	<testSourceDirectory>test/groovy</testSourceDirectory>
	<plugins>
		<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>
				<source>${jdk.version}</source>
				<target>${jdk.version}</target>
			</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.3.7-01</version>
				</dependency>
			</dependencies>
			<executions>
				<execution>
					<phase>test-compile</phase>
					<goals>
						<goal>testCompile</goal>
					</goals>
				</execution>
			</executions>
		</plugin>
		<plugin>
			<groupId>org.grails</groupId>
			<artifactId>grails-maven-plugin</artifactId>
			<version>2.4.4</version>
			<configuration>
				<skipTests>true</skipTests>
				<fork>true</fork>
			</configuration>
			<extensions>true</extensions>
			<executions>
				<execution>
					<goals>
						<goal>package-plugin</goal>
					</goals>
				</execution>
			</executions>
		</plugin>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-surefire-plugin</artifactId>
			<version>2.9</version>
			<executions>
				<execution>
					<phase>test</phase>
					<goals>
						<goal>test</goal>
					</goals>
				</execution>
			</executions>
		</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>grails-app/services</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>test/groovy</source>
							<source>test/java</source>
						</sources>
					</configuration>
				</execution>
				<execution>
					<id>add-test-resource</id>
					<phase>generate-test-sources</phase>
					<goals>
						<goal>add-test-resource</goal>
					</goals>
					<configuration>
						<resources>
							<resource>
								<directory>test/groovy</directory>
								<excludes>
									<exclude>**/*.groovy</exclude>
								</excludes>
							</resource>
						</resources>
					</configuration>
				</execution>
			</executions>
		</plugin>
		<plugin>
			<groupId>org.codehaus.mojo</groupId>
			<artifactId>cobertura-maven-plugin</artifactId>
			<version>2.7</version>
			<configuration>
				<formats>
					<format>html</format>
					<format>xml</format>
				</formats>
			</configuration>
		</plugin>
	</plugins>
</build>
@eric-milles
Copy link
Member

eric-milles commented Jul 24, 2017 via email

@ghost
Copy link
Author

ghost commented Jul 25, 2017

Hi Eric,
Thank you for your response on this. I have tried to place the source under
src/main/java
src/main/groovy

and tests under
src/test/java
src/test/groovy

but still no luck. I see the same issue. Any other pointers on this? I am trying all the possible options :(

Thanks

@PascalSchumacher
Copy link
Member

@gprasann Setting up sourcefolders for the groovy-eclipse-maven plugin is a bit complicated. Have your read https://github.com/groovy/groovy-eclipse/wiki/Groovy-Eclipse-Maven-plugin#setting-up-the-source-folders ?

@eric-milles
Copy link
Member

eric-milles commented Jul 25, 2017 via email

@ghost
Copy link
Author

ghost commented Jul 25, 2017

Thank you @PascalSchumacher and @eric-milles for your replies.

@PascalSchumacher - I have read that link and tried all of the options suggested by moving the source/test files under src/main and directly under src/ with different build options.
For some reason it still fails.

@eric-milles - I am running it as Maven build and not the eclipse build. I have tried the options from the link provided, but no luck.

I am still trying to figureout the issue :(

Thanks

@ghost
Copy link
Author

ghost commented Jul 25, 2017

Now I tried to add maven-surefire-plugin as well and after which the grovy testcases are not at all compiled by the compiler. It really is behaving crazy. I tried to even add build-helper-maven-plugin by moving the source/test files outside of src/main and src/test, still no luck.

Thanks

@eric-milles
Copy link
Member

eric-milles commented Jul 25, 2017

I created a very simple Groovy-Maven project and could compile both main and test sources using Run As > Maven Build... with goals compile and test-compile

groovy-maven
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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <artifactId>Mvn</artifactId>
  <groupId>a.b.c</groupId>
  <version>0.0.1-SNAPSHOT</version>

  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <project.build.sourceEncoding>ASCII</project.build.sourceEncoding>
  </properties>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.6.1</version>
        <configuration>
          <compilerId>groovy-eclipse-compiler</compilerId>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-eclipse-compiler</artifactId>
            <version>2.9.2-01</version>
          </dependency>
          <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-eclipse-batch</artifactId>
            <version>2.4.3-01</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>org.codehaus.groovy</groupId>
      <artifactId>groovy-all</artifactId>
      <version>2.4.12</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

When I run Maven > Update Project... it added the Groovy nature and the source folders src/main/groovy and src/test/groovy. I needed files in src/main/java and src/test/java for this, as described in https://github.com/groovy/groovy-eclipse/wiki/Groovy-Eclipse-Maven-plugin#setting-up-the-source-folders

[INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ Mvn ---
[INFO] Changes detected - recompiling the module!
[INFO] Using Groovy-Eclipse compiler to compile both Java and Groovy files

This last line for compile and test-compile lets you know the Groovy batch compiler is active.

@ghost
Copy link
Author

ghost commented Jul 26, 2017

Hi @eric-milles - Thank you very mmuch for your help on this.
I am not sure what the problem was with whatever I was doing.
Earlier I was creating a grails project and converting it to Maven and it was not working.

Now I followed your approach of creating the Maven project and then converting to Grails and it looks to be working fine.

I am unable to understand the differences between the two approaches, but I am happy that I am able to run it fine now :)

Thanks again all for your help on this.

@ghost
Copy link
Author

ghost commented Jul 26, 2017

Hi @eric-milles - I got the exact issue now.
It is working fine when I use maven packaging Jar, but the moment I convert the packaging to Pom, the testcases wouldn't run along with maven build.
And when I use compiler:testCompile option for maven build, testcases wouldn't find the source files.

Any idea what I am missing here?

Thanks,
Prasann

@eric-milles
Copy link
Member

@gprasann Can you describe the change I would make to my pom.xml to get to this state? I've not used Maven a whole lot.

@ghost
Copy link
Author

ghost commented Jul 26, 2017

Hi @eric-milles, Thank you for the reply. You need to add tag to your pom.xml file as below

<packaging>pom</packaging>

With this we would be able to build grails plugin projects as zip artifacts instead of jar.

Thanks,
Prasann

@eric-milles
Copy link
Member

So once changed to a pom project, I think Maven is expecting a module that contains the sources and tests to be packaged as jar or war or whatever. With pom packaging, my build does not even compile sources.

@ghost
Copy link
Author

ghost commented Jul 26, 2017

Hi @eric-milles - Looks like I have craked it. I am using the default packaging (jar) and I am using the grails-maven-plugin with goal as package-plugin.

With this I had to move source files out of src/main directly under src. And same for test files. Otherwise even the test files are packaged in the plugin artifact (not really sure why)

I also had to use build-helper-maven-plugin to add source and test folders.

Now after doing all this, I am able to build the grails plugin fine with maven.

Hopefully this will help someone who has same problem :)

And Thank you again for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants