简体   繁体   中英

Change Maven Dependency version with Java

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()));
    }

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM