I have non-maven java project. I want to create second project, with maven nature this time to hold all the integration and unit tests for the main application. To run tests from CLI I need to include dependencies from main project into test project in "maven style". As there is no out-of-the-box solution for that I have decided to crate new Maven plugin for that:
So, my plugin would analisye .classpath file of Eclipse and add proper URLs to the collection of compiletime libraries. How can I inject such dependencies from maven plugin?
I have found something on the internet like this:
@Parameter(defaultValue = "${project}", required = true, readonly = true)
private MavenProject project;
and project
has good looking methods like getCompileClasspathElements()
. However for some reasons I cannot use it, because of unresolved dependencies:
Description Resource Path Location Type The project was not built since its build path is incomplete. Cannot find the class file for org.apache.maven.artifact.DependencyResolutionRequiredException. Fix the build path then try building this project include-eclipse-project-maven-plugin Unknown Java Problem
Where can I find this class? Shouldnt it be included in maven-project-plugin
as dependency somewhere? What is correct approach for classpath modification on maven lifecycle runtime?
Here is my POM for the plugin:
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.3.9</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0.8</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.2.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.4</version>
<configuration>
<goalPrefix>include-eclipse-project</goalPrefix>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
<executions>
<execution>
<id>mojo-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
<execution>
<id>help-goal</id>
<goals>
<goal>helpmojo</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>run-its</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<version>1.7</version>
<configuration>
<debug>true</debug>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<pomIncludes>
<pomInclude>*/pom.xml</pomInclude>
</pomIncludes>
<postBuildHookScript>verify</postBuildHookScript>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<settingsFile>src/it/settings.xml</settingsFile>
<goals>
<goal>clean</goal>
<goal>test-compile</goal>
</goals>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>install</goal>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
EDIT:
After changing dependencies in POM, plugin is compilable however injected artifcats into MavenProject
object are ommited during compilation phase.
I am adding deps via
public void setDependencyArtifacts(Set<Artifact> dependencyArtifacts)
And listing via
public Set<Artifact> getArtifacts()