I have multiple POMs that inherit a dependency via their parent. The dependency is not to a maven plugin, but another project that I have created:
<dependency>
<groupId>com.my.name.group</groupId>
<artifactId>id-of-my-artifact</artifactId>
<version>2.3.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
Now I want to remove this from the parent POM file and instead have the children POMs use a custom maven plugin for the same functionality. In that custom maven plugin (which I will create), I want to call/add above dependency. I have tried the following code in a Mojo of the new maven-plugin, but it is not adding the dependency (and gives compilation error):
private MavenProject project;
public void execute() throws MojoExecutionException, MojoFailureException {
try {
// adding a dependency
Dependency dep = new Dependency();
dep.setArtifactId("id-of-my-artifact");
dep.setGroupId("com.my.name.group");
dep.setScope("compile");
dep.setVersion("2.3.0-SNAPSHOT");
List<Dependency> lst = new ArrayList<Dependency>();
lst.add(dep);
project.setDependencies(lst);
} catch (Exception ex) {
getLog().info(String.format("Exception %s: ", ex));
throw new MojoExecutionException("Exception has occurred" + ex);
}
}
Is it possible to do this? If yes, how?
I looked at this related question and the link provided in that. From the external link, it seems that it is not possible. But in that question, OP seems to have figured it out and provided a short answer, but I cannot understand the answer. Could someone please help me out? I am new to Maven.