0

I'm trying to write a maven plugin that is able to auto-update my dependencies. I have a working plug-in that, for now, just compile the maven project it's executed on. I am able to get de Dependency objects, but for I'm not looking for a way to find the possible versions to update to. Is there a way that allows me to check for new versions (local and from central)?

@Override
public void execute() {
    final File directory = project.getBasedir();
    final String[] arguments = {"clean compile"};

    LOGGER.info(String.format("Execute maven at '%s': %s", directory, Arrays.toString(arguments)));
    //System.setProperty("maven.multiModuleProjectDirectory", directory.getAbsolutePath());
    final MavenCli mavenCli = new MavenCli();
    final ByteArrayOutputStream stdOutStream = new ByteArrayOutputStream();
    final ByteArrayOutputStream stdErrStream = new ByteArrayOutputStream();
    final PrintStream stdOutPrint = new PrintStream(stdOutStream);
    final PrintStream stdErrPrint = new PrintStream(stdErrStream);
    final int exitCode = mavenCli.doMain(arguments, directory.getAbsolutePath(), stdOutPrint, stdErrPrint);
    for(Dependency dep : project.getDependencies()) {
        LOGGER.info(String.format("Dependency: %s:%s, version %s", dep.getGroupId(), dep.getArtifactId(), dep.getVersion()));
    }
Nigel
  • 25
  • 5
  • Imo it's not a good idea to autoupdate dependencies - A major update might break your entire code due to a modified API of your dependencies. There's a reason why Maven doesn't have a "most recent" alias for the version string. – Nightara Feb 21 '20 at 13:43
  • I know, that's why I'm trying to get the versions and use the new version to build and test the application. – Nigel Feb 21 '20 at 13:51
  • 2
    Hate for you to feel that you wasted your effort, but there is already a plugin which does this https://www.mojohaus.org/versions-maven-plugin/ – Michael Feb 21 '20 at 14:08
  • maven (self) does it with aether ([related sources..deep from maven-resolver-impl](https://github.com/apache/maven-resolver/blob/master/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultMetadataResolver.java)) – xerx593 Feb 21 '20 at 14:16

1 Answers1

1

Perhaps this post can help you https://stackoverflow.com/a/1172805/12155976

Instead of implementing something that can be done by other plugin, invoke that plugin with your needs from your plugin.

Ausiàs Armesto
  • 301
  • 1
  • 2
  • 10