se.vandmo.dependencylock.maven.LockMojo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dependency-lock-maven-plugin Show documentation
Show all versions of dependency-lock-maven-plugin Show documentation
Maven plugin that makes sure that Maven dependency are not accidentaly changed.
package se.vandmo.dependencylock.maven;
import static org.apache.maven.plugins.annotations.ResolutionScope.TEST;
import java.io.File;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
@Mojo(
name = "lock",
requiresDependencyResolution = TEST)
public final class LockMojo extends AbstractMojo {
@Parameter(
defaultValue = "${basedir}",
required = true,
readonly = true)
private File basedir;
@Parameter(
defaultValue="${project}",
required = true,
readonly = true)
private MavenProject project;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
DependenciesLockFile lockFile = DependenciesLockFile.fromBasedir(basedir);
LockedDependencies existingLockedDependencies = getExistingLockedDependencies(lockFile);
LockedDependencies lockedDependencies = existingLockedDependencies.updateWith(Artifacts.from(project.getArtifacts()));
lockFile.write(lockedDependencies);
}
private LockedDependencies getExistingLockedDependencies(DependenciesLockFile lockFile) {
if (lockFile.exists()) {
return lockFile.read();
} else {
return LockedDependencies.empty();
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy