maven-dependency-plugin icon indicating copy to clipboard operation
maven-dependency-plugin copied to clipboard

[MDEP-839] dependency:list should output a plain list when used with a file

Open jira-importer opened this issue 3 years ago • 14 comments

Christoph Läubrich opened MDEP-839 and commented

There is a parameter to redirect the output to a file:

https://maven.apache.org/plugins/maven-dependency-plugin/list-mojo.html#outputFile

This currently has some issues I would not expect when redirecting such content to a file:

  1. First line in the file is empty
  2. Second line says 'The following files have been resolved:'
  3. next lines are indented
  4. ANSI Escape Characters are emmited e.g. [36m -- module maven.core[0;1;33m (auto)[m

What I would expect:

Each line just contains the raw resolved dependency e.g. "org.apache.maven:maven-core:jar:3.8.6:provided" and no more content is printed out, especially no ANSI Escapes


Remote Links:

jira-importer avatar Nov 27 '22 17:11 jira-importer

Michael Osipov commented

ANSI escapes must not be in the file, that is a bug.

jira-importer avatar Nov 27 '22 22:11 jira-importer

Michael Osipov commented

There is a workaround: Run Maven with -B.

jira-importer avatar Jun 08 '24 17:06 jira-importer

Elliotte Rusty Harold commented

Which command are you running specifically? Different commands run along different code paths and produce different output.

jira-importer avatar Dec 04 '24 11:12 jira-importer

Christoph Läubrich commented

If I remember correctly just a simple ``` dependency:list

jira-importer avatar Dec 04 '24 11:12 jira-importer

Elliotte Rusty Harold commented

so something like:

mvn dependency:list -DoutputFile=temp.txt

jira-importer avatar Dec 04 '24 11:12 jira-importer

Elliotte Rusty Harold commented

Note that depending on what's in the tree there can be other messages here as well. Specifically:

"The following files were skipped:" and "The following files have NOT been resolved:"

This goal does not seem to be meant to produce a machine readable list of dependencies.

jira-importer avatar Dec 04 '24 11:12 jira-importer

Christoph Läubrich commented

Yes the documentation says:

If specified, this parameter causes the dependencies to be written to the path specified instead of the console.

So I would have expected it only prints the dependencies itself in a somewhat machine readable format, at least not something with some strange color codes or arbitrary messages.

jira-importer avatar Dec 04 '24 11:12 jira-importer

Elliotte Rusty Harold commented

I'm unable to reproduce the escape codes in the file:

 mvn org.apache.maven.plugins:maven-dependency-plugin:3.8.1:list -DoutputFile=temp.txt

 

Anyone have a test case that shows this?

jira-importer avatar Jan 27 '25 02:01 jira-importer

Elliotte Rusty Harold commented

I've fixed as much of this as I could reproduce and that we want to fix. I could not reproduce the issue with ANSI escape characters. If anyone can reproduce that in a test case, we can reopen.

jira-importer avatar Feb 10 '25 17:02 jira-importer

Elliotte Rusty Harold commented

I've fixed as much of this as I could reproduce and that we want to fix. I could not reproduce the issue with ANSI escape characters. If anyone can reproduce that in a test case, we can reopen.

@elharo issue is still occurring with 3.9.0; see https://github.com/tiffmaelite/maven-dependency-plugin-ansi-codes-bug

tiffmaelite avatar Dec 16 '25 15:12 tiffmaelite

This might help, but what we really need is a PR against head.

elharo avatar Dec 16 '25 22:12 elharo

I cannot repro that on my MacBook. There might be other issues in play. I do not see the same output you do, even after considering escape characters. In particular I don't see the module lines.

elharo avatar Dec 16 '25 22:12 elharo

OK, now I'm getting somewhere. The bug shows up with Java 17 but but Java 8. Not sure why the JDK makes a difference here, but it does

elharo avatar Dec 16 '25 22:12 elharo

Problem seems likely related to these lines in ResolveDependenciesMojo:

        /* if (outputFile != null) {
            MessageUtils.setColorEnabled(false);
        } else {
            MessageUtils.setColorEnabled(true);
        } */

elharo avatar Dec 16 '25 22:12 elharo

what I don't understand is why mdep-839-list isn't picking up this issue

elharo avatar Dec 18 '25 11:12 elharo

For unclear reasons the integration tests don't use JAnsi. Think I need to add it to the test classpath

elharo avatar Dec 19 '25 13:12 elharo