This is not needed starting with Eclipse 2022-09 (4.25)
From Eclipse 2022-09 the official Eclipse Console supports ANSI escape sequences:
https://www.eclipse.org/eclipse/news/4.25/platform.php#debug-ansi-support.
And the maven support was updated to take advantage of that functionality.
Once per Eclipse workspace: add an external maven installation
From “Preferences” go to “Maven” → “Installations” and click the “Add” button.
Make sure to choose the “External” radio button (default), and point “Installation home:” to the folder where you have a version of maven
installed.
Click “Finish”, then “Apply and Close”.
For each Maven Run Configuration: configure maven run target to force colors
From the main menu “Run” → “Run Configurations” select the “Maven Build” configuration you want to modify.
In the “Main” tab
At the very bottom make sure that the “Maven Runtime” is the EXTERNAL
one you added before.
If it is not, select it from the dropdown.
In the table above that option click “Add” and add a parameter named style.color
with the value always
.
and click “OK”
In the “JRE” tab
Go to the “VM arguments” area and add -Djansi.passthrough=true
Run the modified maven run configuration
The output should show the colors you normally get in command line:
Note
This does not affect running maven tasks when you right-click on the project and choose “Run As” and “Maven clean” or “Maven install”.
Explanations
This is not a problem with the ANSI Console plugin.
It is caused by the fact that Maven and the Jansi library used by Maven try to detect if the current console is tty
(not a redirect).
If they think it is, they refuse to output ANSI color escapes.
To force Maven to output color no matter the console type we need to set style.color=always
.
To force Jansi to output color we need to set -Djansi.passthrough=true
.
The third problem was with the Maven SLF4J binding in Eclipse.
The EMBEDDED
maven that comes with Eclipse uses binds with SimpleLoggerFactory
, which does not output colors.
This is why we have to use an external copy of maven, which comes with its own logger, MavenSimpleLogger
.
So now you know the reason for each of the steps above.
And you also understand a bit better why the right-click “Run As” options don’t work: because there is no way to set the properties that force colors on Maven and Jansi
In order to get to this I had to dig in the Maven sources, Jansi sources, and some of the maven plugins that come with Eclipse :-)
I have a way to force the external maven on everything, and force Jansi to use colors, but not maven itself.
So I can get partial colors (log bevel, but no inside the messages (things like the current step, “BUILD SUCCESS”, and so on).
But this article does not explain how to achieve that.
I think it might be possible to fix everything, but it would be more intrusive.