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()));
    }
4
  • 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. Commented Feb 21, 2020 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. Commented Feb 21, 2020 at 13:51
  • 2
    Hate for you to feel that you wasted your effort, but there is already a plugin which does this mojohaus.org/versions-maven-plugin Commented Feb 21, 2020 at 14:08
  • maven (self) does it with aether (related sources..deep from maven-resolver-impl) Commented Feb 21, 2020 at 14:16

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! I was looking for something like this.
I'm glad it helped you. Don't forget to vote the answer so it will help other users ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.