Skip to content

Instantly share code, notes, and snippets.

@buckett
Created October 9, 2015 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buckett/74a56d2bd1e87b61535c to your computer and use it in GitHub Desktop.
Save buckett/74a56d2bd1e87b61535c to your computer and use it in GitHub Desktop.
Makes maven output coloured, although the -q flag stops working when you do this.
#!/bin/sh
# Simple script to make your copy of maven use coloured output
# Details from http://www.aheritier.net/united-colors-of-maven/
if [[ -z "$M2_HOME" ]]; then
echo \$M2_HOME unset, please set and re-run this script 1>&2
exit 1
fi
cd $M2_HOME || ( echo "\$M2_HOME isn't set to a directory" 1>&2; exit 1)
# Newer versions os log4j have a different logger and aren't on maven's approved broken list, we could "fix this"
mvn -q dependency:get dependency:copy -Dartifact=org.slf4j:slf4j-ext:1.7.5 -DoutputDirectory=lib -Dtransitive=false
mvn -q dependency:get dependency:copy -Dartifact=org.apache.logging.log4j:log4j-api:2.0-beta6 -DoutputDirectory=lib -Dtransitive=false
mvn -q dependency:get dependency:copy -Dartifact=org.apache.logging.log4j:log4j-core:2.0-beta6 -DoutputDirectory=lib -Dtransitive=false
mvn -q dependency:get dependency:copy -Dartifact=org.apache.logging.log4j:log4j-slf4j-impl:2.0-beta6 -DoutputDirectory=lib -Dtransitive=false
rm lib/slf4j-simple* 2>/dev/null
cat > conf/logging/log4j2.xml <<EOF
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<properties>
<property name="maven.logging.root.level">INFO</property>
</properties>
<appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="%highlight{[%p{WARN=WARNING}]} %msg%n%throwable" />
</Console>
</appenders>
<loggers>
<root level="\${sys:maven.logging.root.level}">
<appender-ref ref="console"/>
</root>
</loggers>
</configuration>
EOF
# Without this fix you will get a warning that the logger isn't an approved one.
tempdir=`mktemp -d -t maven-hack`
trap "rm -rf $tempdir" EXIT
cd $tempdir
jar xf ~-/lib/maven-embedder* META-INF/maven/slf4j-configuration.properties
# Log4J not Log4j
sed -i .orig 's/org.slf4j.helpers.Log4jLoggerFactory/org.slf4j.helpers.Log4JLoggerFactory/' META-INF/maven/slf4j-configuration.properties
jar cf logging-fix.jar META-INF
mv logging-fix.jar ~-/lib/ext
@buckett
Copy link
Author

buckett commented Oct 12, 2015

Using this seems to break some plugins, as an example:

[ERROR] Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:2.2:hbm2java (default) on 
project course-signup-hbm: Execution default of goal org.codehaus.mojo:hibernate3-maven-
plugin:2.2:hbm2java failed: An API incompatibility was encountered while executing 
org.codehaus.mojo:hibernate3-maven-plugin:2.2:hbm2java: java.lang.NoSuchMethodError: 
org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment