Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
Description
I would like to be able to copy only the direct dependies without the transitive dependencies for the following use cases:
Using Merge Modules in InstallShield:
a merge module bundles a jar into some re-usable object for InstallShield. So in the pom.xml of my merge module, I have a direct dependency on that perticular jar file. But that jar file also has it's own dependencies, I don't want to copy those other dependencies, I only want that jar file.
Taking this further to building the final installer: this bundles all merge modules. So in the pom.xml of the installer, I have dependencies on merge modules. I don't want to copy any jar dependencies that are below that also.
I already created a Mojo that does all I want but it would be better if this also included in the dependency plugin.
This is the code I have:
package com.mycomp.maven.plugin.msm;
import org.apache.maven.artifact.Artifact ;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.codehaus.plexus.util.FileUtils ;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
/**
- @goal process-resources
- @requiresDependencyResolution
- @description Copy the dependencies for the InstallShield Merge Module
*/
public class MsmProcessResourcesMojo extends AbstractMojo
{
/** - @parameter expression="${ project.artifacts}"
- @required
- @read-only
*/
private Collection artifacts;
/**
- @parameter expression="${project.dependencies}
- @required
- @read-only
*/
private Collection dependencies;
/**
- @parameter expression="${project.build.directory}/resources"
- @required
*/
private File targetDirectory;
/**
- @parameter expression="${stripVersions}" default-value="true"
*/
private boolean stripVersions;
/**
- @parameter expression="${limitToExtension}"
*/
private String limitToExtension;
/**
- @parameter expression="${useSubDirectoryPerType}" default-value="true"
*/
private boolean useSubDirectoryPerType;
public MsmProcessResourcesMojo()
{
}
public void execute() throws MojoExecutionException, MojoFailureException
{
try
{
getLog().info( "Process Resources for InstallShield Merge Module..." );
List firstListArtifacts = getFirstLineArtifacts();
Iterator iterator = firstListArtifacts.iterator();
while (iterator.hasNext())
{
Artifact artifact = (Artifact)iterator.next();
if (limitToExtension == null || limitToExtension.equals( artifact.getType() ))
{
File targetDir;
if( useSubDirectoryPerType )
else
{ targetDir = targetDirectory; } getLog().info( "Copying artifact: " + artifact.toString() );
if (stripVersions)
else
{ FileUtils.copyFileToDirectory( artifact.getFile(), targetDir ); } }
}
}
catch (IOException e)
}
private List getFirstLineArtifacts()
{
List result = new ArrayList( dependencies.size() );
Iterator iterator = artifacts.iterator();
while (iterator.hasNext ())
{
Artifact artifact = (Artifact)iterator.next();
if (artifactIsADirectDependency( artifact ))
}
return result;
}
private boolean artifactIsADirectDependency( Artifact artifact )
{
boolean result = false;
Iterator iterator = dependencies.iterator();
while ( iterator.hasNext())
{
Dependency dependency = (Dependency)iterator.next();
if (dependency.getGroupId().equals( artifact.getGroupId() )
&& dependency.getArtifactId ().equals( artifact.getArtifactId() ))
}
return result;
}
}
Note that I have 2 additional options:
- limitToExtension: if you only want to copy dependencies with a certain extension (e.g. only .msm or .dll files for example)
- useSubDirectoryPerType: this will create a structure as follows (simular to m1 repo) :
- root dir
- dlls
- mydll.dll
- msms
- mymsm.dll
regards,
Wim