Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize colors in maven 3.5 console output

Tags:

maven

console

Maven 3.5.0 introduces coloring in console output.

It's a cool feature, however I don't like some default color choices, for example intensive blue INFO looks too distracting.

Is it possible to customize colors somehow?

like image 912
Ilya Avatar asked Apr 15 '17 11:04

Ilya


1 Answers

Turns out it is possible.

Maven uses several styles to format its output:

enum Style
{

    DEBUG(   "bold,cyan"   ),
    INFO(    "bold,blue"   ),
    WARNING( "bold,yellow" ),
    ERROR(   "bold,red"    ),
    SUCCESS( "bold,green"  ),
    FAILURE( "bold,red"    ),
    STRONG(  "bold"        ),
    MOJO(    "green"       ),
    PROJECT( "cyan"        );
...
}

You can override the default color of a style with the system property style.style_name. For example to change the style of INFO from default blue to dark gray you pass

-Dstyle.info=bold,black

option to maven. It also can be specified with MAVEN_OPTS environment variable in order not to type it on every maven invocation.

If you don't know which style is used in the particular part of output, you can match it by its default color.

The colors that can be used in a style are defined by jansi library:

public enum Color {
        BLACK(0, "BLACK"),
        RED(1, "RED"),
        GREEN(2, "GREEN"),
        YELLOW(3, "YELLOW"),
        BLUE(4, "BLUE"),
        MAGENTA(5, "MAGENTA"),
        CYAN(6, "CYAN"),
        WHITE(7, "WHITE"),
        DEFAULT(9, "DEFAULT");
}

Seems that you can prefix color with bg to specify the background color, and to make it intensive, you add bold modifier, for example: bold,white,bgcyan — intensive white on cyan background.

like image 69
Ilya Avatar answered Nov 09 '22 07:11

Ilya