'How do I remove colors from Maven output?

When I run a maven goal in Jenkins (e.g. "mvn test"), the logs are very hard to read because of the color control characters that appear (see example below). Is there anyway to remove the color formatting?

[[1;34mINFO[m] [1m-------------------------------------------------------------------[m
[[1;34mINFO[m] [1;32mBUILD SUCCESS[m
[[1;34mINFO[m] [1m-------------------------------------------------------------------[m
[[1;34mINFO[m] Total time: 16.097 s
[[1;34mINFO[m] Finished at: 2017-04-26T11:23:06-04:00
[[1;34mINFO[m] Final Memory: 41M/100M
[[1;34mINFO[m] [1m-------------------------------------------------------------------[m


Solution 1:[1]

--batch-mode, mentioned in other answers, is usually a better option for non-interactive execution, like in a CI server, but if you want just to turn off the color, it is possible since maven 3.5.1 using the following option:

mvn -Dstyle.color=never

other options for this parameter are always or auto.

Solution 2:[2]

maven --batch-mode will do. However, if you have to inspect some already-generated output that contains those colour codes, you can use sed to strip the codes away, as it's explained here.

Solution 3:[3]

Jenkins Maven plugin example of batch mode -B (remove color tags) and silent mode -q inside pipeline script:

rtMaven = Artifactory.newMavenBuild()
...
rtMaven.run pom: 'pom.xml',
            goals: "-q -B clean compiler:compile" 

Solution 4:[4]

set env

MAVEN_OPTS="$MAVEN_OPTS -Dmaven.color=false"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 zakmck
Solution 3 MichalSv
Solution 4 Suraj Rao