Can't control log4j when running all maven tests - java

In src/test/resources/log4j.properties I've configured log4j to not log anything.
When I run a single test, i.e. mvn clean test -Dtest=MyTestClass, this log4j properties is heeded. However, when I run all the tests, i.e. mvn clean test, this logging conf is ignored. How can this be?!!
I think I'm going crazy but hope there's a logical explanation :-)
Any help is highly appreciated.
$ mvn -version
Apache Maven 3.3.9
Maven home: /usr/share/maven
Java version: 1.8.0_60, vendor: Oracle Corporation
Java home: /usr/lib/jvm/jdk-8-oracle-x64/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "4.6.0-1-amd64", arch: "amd64", family: "unix"
The sure fire version is 2.19.1:
[INFO] --- maven-surefire-plugin:2.19.1:test (default-test) # common-util ---
The src/test/resources/log4j.properties:
log4j.rootLogger=OFF
POM fragments related to resources:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>ISO-8859-1</encoding>
</configuration>
</plugin>

One of the 52 test classes under src/test/java had the following lines in its #Before method:
import org.apache.log4j.BasicConfigurator;
#Before
public void setUp() {
BasicConfigurator.resetConfiguration();
BasicConfigurator.configure();
}
For some reason, what must be a bug as far as I can tell, these calls to log4j affects all other junit classes too. Removing these lines made mvn test got the same logging behaviour as running mvn test -Dtest=MyTestClass, i.e. what was defined in src/test/resources/log4j.properties.

Related

How can I make maven-metadata.xml have the same timestamp as the artifact wen deployed with maven?

I have a Nexus 3 which I deploy some artifacts from Jenkins with "mvn deploy". I have A LOT of modules 500+. The build looks kind of like this:
mvn clean package -DskipTests -DskipITs -T C1
mvn install -DskipTests -DskipITs -T C1
mvn deploy --quiet -DskipTests -DskipITs -Dmaven.validate.skip=true -Dmaven.compile.skip=true -Dmaven.test.skip=true -Dmaven.package.skip=true -Dmaven.integration-test.skip=true -Dmaven.verify.skip=true -T C1
The problem is that from time to time my artifacts have a timestamp while the metadata has a different timestamp. 1 second difference usually.
This is what I see in nexus at https://mynexus.com/repository/snapshots/com/company/my-artifact/1.0.0-SNAPSHOT/maven-metadata.xml
<?xml version="1.0" encoding="UTF-8"?>
<metadata modelVersion="1.1.0">
<groupId>com.company</groupId>
<artifactId>my-artifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
<versioning>
<snapshot>
<timestamp>20170613.140447</timestamp>
<buildNumber>1</buildNumber>
</snapshot>
<lastUpdated>20170613140447</lastUpdated>
<snapshotVersions>
<snapshotVersion>
<extension>war</extension>
<value>1.0.0-20170613.140447-1</value>
<updated>20170613140447</updated>
</snapshotVersion>
<snapshotVersion>
<extension>pom</extension>
<value>1.0.0-20170613.140447-1</value>
<updated>20170613140447</updated>
</snapshotVersion>
</snapshotVersions>
</versioning>
</metadata>
Judging the maven-metadata.xml, the artifact URL should be this:
https://mynexus.com/repository/snapshots/com/company/my-artifact/1.0.0-SNAPSHOT/my-artifact/1.0.0-20170613.140447-1.war
But it is not. Instead, the artifact is at this location:
https://mynexus.com/repository/snapshots/com/company/my-artifact/1.0.0-SNAPSHOT/my-artifact/1.0.0-20170613.140446-1.war
mvn --version
OpenJDK 64-Bit Server VM
Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-03T21:39:06+02:00)
Maven home: /usr/local/apache-maven
Java version: 1.8.0_131, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-64-generic", arch: "amd64", family: "unix"
The version of maven-deploy-plugin is 2.8.2
What am I doing wrong? How can I fix this?
Thank you!
This is a bug in Maven 3.5.0 and and will be resolved whenever 3.5.1 is released.
The original bug-report targed the deploy-plugin (https://issues.apache.org/jira/browse/MDEPLOY-221) however it's an issue with maven core: https://issues.apache.org/jira/browse/MNG-6240.
We hit the same issue at my work and after some digging and searching on mavens issue tracker I found the above links. I would suggest downgrading while waiting for 3.5.1 to come out.

Maven non-interactive mode (batch) prevent's project extensions loading

I'm trying to use Takari SmartBuilder in a Maven project under Jenkins.
After testing it locally everything was working perfectly, but in Jenkins the Takari extension is not loaded.
After some investigation I found that maven's "-B" option order was preventing the projects extensions to load.
Not loading extensions:
mvn -B -f <project-name>/pom.xml clean install -X
Loading extensions:
mvn -f <project-name>/pom.xml -B clean install -X
Extensions are set in the root project folder under .mvn/extensions.xml
<?xml version="1.0" encoding="UTF-8"?>
<extensions>
<extension>
<groupId>io.takari.maven</groupId>
<artifactId>takari-smart-builder</artifactId>
<version>0.4.0</version>
</extension>
<extension>
<groupId>io.takari.aether</groupId>
<artifactId>takari-concurrent-localrepo</artifactId>
<version>0.0.7</version>
</extension>
<extension>
<groupId>io.takari.aether</groupId>
<artifactId>aether-connector-okhttp</artifactId>
<version>1.0.1-alpha</version>
</extension>
</extensions>
Versions:
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T16:41:47+00:00)
Maven home: /opt/maven-versions/apache-maven-3.3.9
Java version: 1.7.0_65, vendor: Oracle Corporation
Java home: /opt/java-versions/jdk1.7.0_65/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-327.13.1.el7.x86_64", arch: "amd64", family: "unix"
I believe I am facing a similar issue.
see https://issues.jenkins.io/browse/JENKINS-70357
It seems that the Jenkins Maven Integration Plugin is injecting the -B parameter unconditionally and for a good reason I am afraid.
However, either with or without interactive mode enabled, the extensions are loaded successfully (from lib/ext though), which proves that interactive mode does not control extensions in any way.
Also, using MavenJob offers some substantial advantages, like triggering downstream builds etc., which cannot be used with FreeStyleJob, making use of MavenJob necessary for certain development environments.

Minify Maven Plugin throwing "JavaScript engine not supported" error

How can I configure the Minify Maven Plugin plugin to work with Maven 2.2.1 while also using the Google Closure Compiler?
According to this issue, Version 1.7.1 should work with that particular version of Maven, but on minification, it is throwing this warning: "[WARNING] JavaScript engine not supported". The concatenation of the bundles works as expected. I am upgrading from version 1.2.4 to the utilize the the Closure Compiler. I need Closure Compiler as YUI has some unresolved bugs with certain ES2015 syntax. We won't be upgrading to Maven 3 for a while.
workstation details:
java version "1.8.0_60"
Apache Maven 2.2.1 (r801777; 2009-08-06 12:16:01-0700)
Java version: 1.8.0_60
OS name: "mac os x" version: "10.10.4" arch: "x86_64" Family: "mac"
My configuration:
<plugin>
<groupId>com.samaxes.maven</groupId>
<artifactId>minify-maven-plugin</artifactId>
<version>1.7.1</version>
<executions>
<execution>
<id>someBundle</id>
<phase>process-classes</phase>
<configuration>
<webappSourceDir>web/src/static${static.asset.basedir}</webappSourceDir>
<webappTargetDir>web/target/minify</webappTargetDir>
<jsSourceFiles>
<param>libs/somelib.js</param>
<param>libs/anotherlib.js</param>
</jsSourceFiles>
<jsFinalFile>bundle.js</jsFinalFile>
<jsEngine>CLOSURE</jsEngine>
</configuration>
<goals>
<goal>minify</goal>
</goals>
</execution>
</executions>
</plugin>
This question was pretty obscure so I'll answer it by posting my solution. I was fearful that upgrading to Maven 3 would open up a can of worms, but it didn't. As a matter of fact, it just worked after changing the location of the Maven home directory (in IntelliJ and in the zsh profile - M2_HOME) and the location of our Maven Repository (which was not in the default location). I build with both IntelliJ and by command line so both locations needed to be updated.
New home directory location (installed with Homebrew):
/usr/local/Cellar/maven/3.3.3/libexec
Local Maven repository setting updated in this file:
/usr/local/Cellar/maven/3.3.3/libexec/conf/settings.xml
Update this value:
<localRepository>/path/to/local/maven/repository/</localRepository>

javac: invalid target release: 1.8 on Mac when executing Maven command

I am trying to run automation test on Mac. I installed Maven and java, jdk as following:
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
and Maven:
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T18:29:23+01:00)
Maven home: /usr/local/Cellar/maven/3.2.5/libexec
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.9.5", arch: "x86_64", family: "mac"
When I executed Maven command, I got this error:
[ERROR] Failure executing javac, but could not parse the error:
[ERROR] javac: invalid target release: 1.8
[ERROR] Usage: javac <options> <source files>
[ERROR] use -help for a list of possible options
[ERROR] -> [Help 1]
I searched on here, there's one accepted solution is this:
sudo cp $JAVA_HOME/lib/tools.jar /Library/Java/Extensions/
I executed this command, but nothing happened! I don't know what's wrong.
First, figure out where 1.8 Java is installed by running the command:
/usr/libexec/java_home -v 1.8
Then, set your JAVA_HOME environment variable by running the command:
export JAVA_HOME=<whatever the output from the previous command was>
Maven should work afterwards, at least in that terminal window.
You'll have to set the JAVA_HOME environment variable in your profile if you don't want to have to run these commands every time you open a new terminal.
If you haven't done so already, use the maven-compiler-plugin to determine the Java version to use within Maven. Put this in your pom.xml file (change the <source/> and <target/> version to the JDK version you require):
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
(If you already have a <build/> and/or <plugins/> section, add the <plugin/> portion, only.)

Maven doesnt use specified source and target settings

I'm trying to build a java project using maven. In the pom.xml file at the root of the project I have the following lines:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<debug>true</debug>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
but when I try to build with mvn -DskipTests -U install, I get the following error: static import declarations are not supported in -source 1.3
maven is not using the source and target (1.6) that i've specified in the pom.
java -version
java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)
mvn --version
Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.7.0_11, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-oracle
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.5.0-21-generic", arch: "amd64", family: "unix"
uname -a
Linux ubuntu 3.5.0-21-generic #32-Ubuntu SMP Tue Dec 11 18:51:59 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
Is there anywhere else that maven might be getting its default source and target settings from? Why isnt it using the settings from the pom?
Here is a snippet of error message when maven is ran in debug mode:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project LeaderLines: Compilation failure
[ERROR] /path/geoserver-2.2/geotools-plugin/LeaderLines/src/org/geotools/filter/function/FilterFunction_leaderLine.java:[22,7] error: static import declarations are not supported in -source 1.3
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins: maven-compiler-plugin:2.0.2:compile (default-compile) on project LeaderLines: Compilation failure
/path/geoserver-2.2/geotools-plugin/LeaderLines/src/org/geotools/filter/function/FilterFunction_leaderLine.java:[22,7] error: static import declarations are not supported in -source 1.3
Try setting the source level and source encoding with the following properties:
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Try to clear you local Maven repo and run your build again (maybe, try also to run it with '-o' option)

Categories

Resources