Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
Expand Down Expand Up @@ -97,6 +98,15 @@ public abstract class AbstractAppAssemblerMojo
@Parameter( defaultValue = "false" )
protected boolean preClean;

/**
* If set to {@code true}, overwrites existing dependencies in the repository. If set to {@code false},
* it will check if the dependency is already present in the repository prior copying to it.
*
* @since 2.0.1
*/
@Parameter( defaultValue = "true" )
protected boolean overwriteDependencies;

// -----------------------------------------------------------------------
// Read-only parameters
// -----------------------------------------------------------------------
Expand Down Expand Up @@ -169,10 +179,11 @@ protected ArtifactRepositoryLayout getArtifactRepositoryLayout()
* @param artifact The artifact to install.
* @param artifactRepository The repository where to install.
* @param useTimestampInSnapshotFileName Using timestamp for SNAPSHOT's.
* @param overwriteExistingArtifacts Set to {@code false} to avoid overwriting existing artifacts.
* @throws MojoExecutionException
*/
protected void installArtifact( Artifact artifact, ArtifactRepository artifactRepository,
boolean useTimestampInSnapshotFileName )
boolean useTimestampInSnapshotFileName, boolean overwriteExistingArtifacts )
throws MojoExecutionException
{
if ( artifact != null && artifact.getFile() != null )
Expand Down Expand Up @@ -206,13 +217,28 @@ protected void installArtifact( Artifact artifact, ArtifactRepository artifactRe
String fileName = MappingUtils.evaluateFileNameMapping( outputFileNameMapping, artifact );
destination = new File( destination.getParent(), fileName );
}
// Sometimes target/classes is in the artifact list and copyFile() would fail.
// Need to ignore this condition
FileUtils.copyFile( source, destination );
}

getLog().info( "Installing artifact " + source.getPath() + " to " + destination );
if ( overwriteExistingArtifacts )
{
// Sometimes target/classes is in the artifact list and copyFile() would fail.
// Need to ignore this condition
FileUtils.copyFile( source, destination );
getLog().info( "Installing artifact " + source.getPath() + " to " + destination );
}
else
{
if ( !Files.exists( destination.toPath() ) )
{
FileUtils.copyFile( source, destination );
}
else
{
destination.setLastModified(System.currentTimeMillis()); //'touches' the file
}

getLog().info( "Skiped installing artifact " + source.getPath() + " to " + destination + ". File already exists.");
}
}
}
catch ( IOException e )
{
Expand All @@ -235,7 +261,7 @@ protected void installArtifact( Artifact artifact, ArtifactRepository artifactRe
protected void installArtifact( Artifact artifact, ArtifactRepository artifactRepository )
throws MojoExecutionException
{
installArtifact( artifact, artifactRepository, true );
installArtifact( artifact, artifactRepository, true, true );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ protected void installDependencies( final String outputDirectory, final String r

for ( Artifact artifact : artifacts )
{
installArtifact( artifact, artifactRepository, this.useTimestampInSnapshotFileName );
installArtifact( artifact, artifactRepository, this.useTimestampInSnapshotFileName, true );
}

// install the project's artifact in the new repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void execute()
// TODO: merge with the artifacts below so no duplicate versions included
for ( Artifact artifact : artifacts )
{
installArtifact( artifact, artifactRepository, this.useTimestampInSnapshotFileName );
installArtifact( artifact, artifactRepository, this.useTimestampInSnapshotFileName, overwriteDependencies );
}

if ( installBooterArtifacts )
Expand Down Expand Up @@ -189,7 +189,7 @@ private void installBooterArtifacts( ArtifactRepository artifactRepository )
for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); )
{
Artifact a = (Artifact) i.next();
installArtifact( a, artifactRepository, this.useTimestampInSnapshotFileName );
installArtifact( a, artifactRepository, this.useTimestampInSnapshotFileName, true );
}
}
catch ( ArtifactResolutionException e )
Expand Down