Skip to content

Commit

Permalink
Fix multi-module classpath issues (closes #183)
Browse files Browse the repository at this point in the history
  • Loading branch information
keeganwitt committed Dec 11, 2020
1 parent 69c9dc3 commit 5816788
Show file tree
Hide file tree
Showing 28 changed files with 332 additions and 907 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.11.2-SNAPSHOT</version>
<version>1.12.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
55 changes: 55 additions & 0 deletions src/it/multimodulePluginAndProjectClasspath/a/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>

<parent>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin-it-multimodulePluginAndProjectClasspath</artifactId>
<version>testing</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>gmavenplus-plugin-it-multimodulePluginAndProjectClasspath-a</artifactId>
<version>testing</version>
<name>GMavenPlus Plugin Multi-Module Plugin and Project Classpath Test A Module</name>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>execute</goal>
</goals>
</execution>
</executions>
<configuration>
<scripts>
<script><![CDATA[
assert Class.forName('org.junit.Test') != null
try {
Class.forName('org.junit.jupiter.api.Test')
assert null != null // should throw exception and never reach
} catch (ClassNotFoundException e) {
// do nothing, this is expected
}
]]></script>
</scripts>
</configuration>
</plugin>
</plugins>
</build>

</project>
55 changes: 55 additions & 0 deletions src/it/multimodulePluginAndProjectClasspath/b/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>

<parent>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin-it-multimodulePluginAndProjectClasspath</artifactId>
<version>testing</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>gmavenplus-plugin-it-multimodulePluginAndProjectClasspath-b</artifactId>
<version>testing</version>
<name>GMavenPlus Plugin Multi-Module Plugin and Project Classpath Test B Module</name>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>execute</goal>
</goals>
</execution>
</executions>
<configuration>
<scripts>
<script><![CDATA[
assert Class.forName('org.junit.jupiter.api.Test') != null
try {
Class.forName('org.junit.Test')
assert null != null // should throw exception and never reach
} catch (ClassNotFoundException e) {
// do nothing, this is expected
}
]]></script>
</scripts>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals=clean test
#invoker.debug = true
125 changes: 125 additions & 0 deletions src/it/multimodulePluginAndProjectClasspath/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>

<parent>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin-it-root</artifactId>
<version>testing</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>gmavenplus-plugin-it-multimodulePluginAndProjectClasspath</artifactId>
<version>testing</version>
<name>GMavenPlus Plugin Multi-Module Plugin and Project Classpath Test</name>
<packaging>pom</packaging>

<profiles>
<profile>
<id>indy</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<dependencies>
<dependency>
<groupId>@groovyGroupId@</groupId>
<artifactId>groovy</artifactId>
<version>@groovyVersion@</version>
<classifier>indy</classifier>
</dependency>
<dependency>
<groupId>@groovyGroupId@</groupId>
<artifactId>groovy-ant</artifactId>
<version>@groovyVersion@</version>
<classifier>indy</classifier>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>nonindy</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<dependencies>
<dependency>
<groupId>@groovyGroupId@</groupId>
<artifactId>groovy</artifactId>
<version>@groovyVersion@</version>
</dependency>
<dependency>
<groupId>@groovyGroupId@</groupId>
<artifactId>groovy-ant</artifactId>
<version>@groovyVersion@</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>pre2.3-indy</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<dependencies>
<dependency>
<groupId>@groovyGroupId@</groupId>
<artifactId>groovy</artifactId>
<version>@groovyVersion@</version>
<classifier>indy</classifier>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>pre2.3-nonindy</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<dependencies>
<dependency>
<groupId>@groovyGroupId@</groupId>
<artifactId>groovy</artifactId>
<version>@groovyVersion@</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</build>

<modules>
<module>a</module>
<module>b</module>
</modules>

</project>
8 changes: 8 additions & 0 deletions src/it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<project.build.sourceEncoding>@project.build.sourceEncoding@</project.build.sourceEncoding>
<commonsLang3Version>3.7</commonsLang3Version>
<mavenVersion>3.6.3</mavenVersion>
<junit5Version>5.7.0</junit5Version>
</properties>

<dependencyManagement>
Expand All @@ -23,6 +24,13 @@
<version>@junitVersion@</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>${junit5Version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import java.net.MalformedURLException;
import java.util.List;

import static java.util.Collections.emptyList;


/**
* The base mojo class, which all other mojos extend.
Expand Down Expand Up @@ -238,10 +240,13 @@ protected boolean isGroovyIndy() {
protected void setupClassWrangler(List<?> classpath, IncludeClasspath includeClasspath) throws MalformedURLException {
if (IncludeClasspath.PROJECT_ONLY.equals(includeClasspath)) {
getLog().info("Using isolated classloader, without GMavenPlus classpath.");
classWrangler = new ClassWrangler(classpath, getLog());
classWrangler = new ClassWrangler(classpath, ClassLoader.getSystemClassLoader(), getLog());
} else if (IncludeClasspath.PROJECT_AND_PLUGIN.equals(includeClasspath)) {
getLog().info("Using plugin classloader, includes GMavenPlus and project classpath.");
classWrangler = new ClassWrangler(classpath, getClass().getClassLoader(), getLog());
} else {
getLog().info("Using plugin classloader, includes GMavenPlus classpath.");
classWrangler = new ClassWrangler(Thread.currentThread().getContextClassLoader(), getLog());
getLog().info("Using plugin classloader, includes GMavenPlus classpath, but not project classpath.");
classWrangler = new ClassWrangler(emptyList(), getClass().getClassLoader(), getLog());
}
}
}
3 changes: 1 addition & 2 deletions src/main/java/org/codehaus/gmavenplus/mojo/CompileMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
* @author Keegan Witt
* @since 1.0-beta-1
*/
@Mojo(name = "compile", defaultPhase = LifecyclePhase.COMPILE, requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true,
configurator = "include-project-compile-dependencies")
@Mojo(name = "compile", defaultPhase = LifecyclePhase.COMPILE, requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true)
public class CompileMojo extends AbstractCompileMojo {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
* @author Keegan Witt
* @since 1.0-beta-1
*/
@Mojo(name = "compileTests", defaultPhase = LifecyclePhase.TEST_COMPILE, requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true,
configurator = "include-project-test-dependencies")
@Mojo(name = "compileTests", defaultPhase = LifecyclePhase.TEST_COMPILE, requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true)
public class CompileTestsMojo extends AbstractCompileMojo {

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/codehaus/gmavenplus/mojo/ConsoleMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
* @author Keegan Witt
* @since 1.1
*/
@Mojo(name = "console", requiresDependencyResolution = ResolutionScope.TEST, configurator = "include-project-test-dependencies")
@Mojo(name = "console", requiresDependencyResolution = ResolutionScope.TEST)
public class ConsoleMojo extends AbstractToolsMojo {

/**
Expand Down Expand Up @@ -178,7 +178,7 @@ protected Object setupConsole(final Class<?> consoleClass, final Class<?> bindin
invokeMethod(setVariable, binding, "properties", properties);
}

return invokeConstructor(findConstructor(consoleClass, ClassLoader.class, bindingClass), Thread.currentThread().getContextClassLoader(), binding);
return invokeConstructor(findConstructor(consoleClass, ClassLoader.class, bindingClass), classWrangler.getClassLoader(), binding);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/codehaus/gmavenplus/mojo/ExecuteMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
* @author Keegan Witt
* @since 1.0-beta-1
*/
@Mojo(name = "execute", requiresDependencyResolution = ResolutionScope.TEST, configurator = "include-project-test-dependencies", threadSafe = true)
@Mojo(name = "execute", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true)
public class ExecuteMojo extends AbstractToolsMojo {

/**
Expand Down Expand Up @@ -174,9 +174,9 @@ protected Object setupShell(final Class<?> groovyShellClass) throws InvocationTa
Class<?> compilerConfigurationClass = classWrangler.getClass("org.codehaus.groovy.control.CompilerConfiguration");
Object compilerConfiguration = invokeConstructor(findConstructor(compilerConfigurationClass));
invokeMethod(findMethod(compilerConfigurationClass, "setSourceEncoding", String.class), compilerConfiguration, sourceEncoding);
shell = invokeConstructor(findConstructor(groovyShellClass, compilerConfigurationClass), compilerConfiguration);
shell = invokeConstructor(findConstructor(groovyShellClass, ClassLoader.class, compilerConfigurationClass), classWrangler.getClassLoader(), compilerConfiguration);
} else {
shell = invokeConstructor(findConstructor(groovyShellClass));
shell = invokeConstructor(findConstructor(groovyShellClass, ClassLoader.class), classWrangler.getClassLoader());
}
initializeProperties();
Method setProperty = findMethod(groovyShellClass, "setProperty", String.class, Object.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
* @author Keegan Witt
* @since 1.0-beta-1
*/
@Mojo(name = "generateStubs", defaultPhase = LifecyclePhase.GENERATE_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true,
configurator = "include-project-compile-dependencies")
@Mojo(name = "generateStubs", defaultPhase = LifecyclePhase.GENERATE_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true)
public class GenerateStubsMojo extends AbstractGenerateStubsMojo {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
* @author Keegan Witt
* @since 1.0-beta-1
*/
@Mojo(name = "generateTestStubs", defaultPhase = LifecyclePhase.GENERATE_TEST_SOURCES, requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true,
configurator = "include-project-test-dependencies")
@Mojo(name = "generateTestStubs", defaultPhase = LifecyclePhase.GENERATE_TEST_SOURCES, requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true)
public class GenerateTestStubsMojo extends AbstractGenerateStubsMojo {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
* @author Keegan Witt
* @since 1.7.1
*/
@Mojo(name = "groovydoc-jar", defaultPhase = LifecyclePhase.PACKAGE, requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true,
configurator = "include-project-compile-dependencies")
@Mojo(name = "groovydoc-jar", defaultPhase = LifecyclePhase.PACKAGE, requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true)
public class GroovyDocJarMojo extends GroovyDocMojo {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @author Keegan Witt
* @since 1.0-beta-1
*/
@Mojo(name = "groovydoc", requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true, configurator = "include-project-compile-dependencies")
@Mojo(name = "groovydoc", requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true)
public class GroovyDocMojo extends AbstractGroovyDocMojo {

/**
Expand Down

0 comments on commit 5816788

Please sign in to comment.