Unable to suppress excessive logs from scalatest-maven-plugin - logback

Background
I am facing excessive logging from default Logger when I run scala tests from maven because it is not picking up the logback.xml on the classpath with the correct logging definitions
So my maven config is fairly generic (as per scalatest-maven-plugin docs)
Looks like this
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<!-- enable scalatest -->
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<junitxml>.</junitxml>
<filereports>MyProj_TestSuite.txt</filereports>
<forkMode>never</forkMode>
</configuration>
<executions>
<execution>
<id>test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
I have a logback.xml in my src/main/resources which gets copied over to target/classes
Things I tried so far
Have spent a whole day to figure out why this is not being picked up -- using the following configuration optional entries
<runpath>
${project.basedir}/target/classes
</runpath>
<systemProperties>
<logback.configurationFile> ${project.basedir}/src/main/resources/logback.xml</logback.configurationFile>
</systemProperties>
<argLine>
-Dlogback.configurationFile=src/main/resources/logback.xml
</argLine>
If I run it like this (from command line) from ${project.basedir}
mvn test -Dlogback.configurationFile=./src/test/resources/logback.xml
it works
I have looked at similar issues on stack and even tried adding this
<build>
<testResources>
<testResource>
<directory>${project.basedir}/target/classes</directory>
</testResource>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
</build>
This did not work - I think it is because I am using scala-maven-test plugin which has its own configuration block.
Any help on how to do this from inside the pom.xml will be much appreciated.

Try to have /src/test/resources/logback-test.xml logback configuration file.
It works for me with scalatest-maven-plugin of 2.0.2 version.

Related

The generated IntegrationContent client code miss several methods

I generated the client code of IntegrationContent following the guidance(https://api.sap.com/api/IntegrationContent/cloud-sdk/Java) https://api.sap.com/api/IntegrationContent/cloud-sdk/Java.
According to the guidance, I downloaded the edmx,and config my maven plugin as below.
Acctually, I generated the code; but comparing to the apihub(https://api.sap.com/api/IntegrationContent/resource), some methods are lost.
Can anyone help on this?
<plugin>
<groupId>com.sap.cloud.sdk.datamodel</groupId>
<artifactId>odata-generator-maven-plugin</artifactId>
<!-- Please use always the latest version. You can find it on this page.-->
<version>3.64.0</version>
<executions>
<execution>
<id>generate-consumption</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputDirectory>${project.basedir}/edmx</inputDirectory>
<outputDirectory>${project.build.directory}/vdm</outputDirectory>
<deleteOutputDirectory>true</deleteOutputDirectory>
<packageName>com.sample</packageName>
<defaultBasePath>odata/v4/</defaultBasePath>
<compileScope>COMPILE</compileScope>
<serviceMethodsPerEntitySet>true</serviceMethodsPerEntitySet>
</configuration>
</execution>
</executions>
</plugin>

maven-jaxb2-plugin ignoring configuration

I'm using maven 3.3.9 and the maven-jaxb2-plugin 0.13.1. But when I try to generate the Java classes, the plugin is not finding my XSD-file.
My pom looks like this:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/schemas</schemaDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
Everytime I'm executing the goal, I get this message:
[WARNING] No schemas to compile. Skipping XJC execution.
The directory exists under the resources folder, and the XSD is placed there. I have no other pom-files in play.
Any help would be very much appreciated
In case anyone else will hit this. I had a similar issue: the configuration was not picked up by the plugin. I made it work by moving configuration section under plugin declaration instead of execution.
Here's how the working configuration looked like for me (I removed the upper-level elements since they do not matter):
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.15.1</version>
<configuration>
<schemaDirectory>src/main/resources/custom-schemas</schemaDirectory>
</configuration>
<executions>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
/executions>
</plugin>
Author of maven-jaxb2-plugin here.
Somehow I have a feeling that you're omitting important details. This does not not add up. This is a very basic configuration setting, I'm curious how it can't work.
You only post the pluginManagement part of your pom.xml. If you have just this, it should not work at all as it is just and only a declaration of configuration, not actual usage of the plugin. You need plugins/plugin to actually apply the plugin:
<project ...>
...
<build>
<plugins>
...
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>...</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
...
</project>
To analyze the problem, run mvn -X clean generate-sources or mvn -X clean install and check the applied configuration (it will be logged). Post the log here.
If this does not help, send me a PR of a minimal reproducing project under https://github.com/highsource/maven-jaxb2-plugin-support/s/schemaDirectory, I'll take a look.

Adding properties to manifest file with spring boot

I want to add SplashScreen-Image: <image name> to the manifest file.
How do I do this with Spring Boot's Maven Plugin? If this is not possible, how do I create a single executable jar using maven with additional properties?
The answer was kinda obvious in hindsight. Spring-Boot's maven plugin rewrites the original manifest file so using the maven jar plugin the manifest can be written as normal. Like this:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<splashscreen-image>${image.name}</splashscreen-image>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>

IntelliJ Error when running unit test: Could not find or load main class ${surefireArgLine}

I get the following error when running Unit tests in IntelliJ:
Error: Could not find or load main class ${surefireArgLine}.
I am using maven and in pom.xml I have:
<properties>
...
<surefire.argLine />
</properties>
<build>
<plugins>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<!--Sets the VM argument line used when unit tests are run.-->
<argLine>${surefire.argLine}</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.1.201405082137</version>
<executions>
<!--
Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Surefire plugin is executed.
-->
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!--Sets the path to the file which contains the execution data.-->
<destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
<!--
Sets the name of the property containing the settings
for JaCoCo runtime agent.
-->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
...
Did anyone have similiar problem? How to set value for surefireArgLine?
I had the same problem and i think i found the solution on the vertx-issue tracker.
In short you have to configure your IntelliJ Maven (surefire plugin) integration to behave differently.
This works for me in IntelliJ 14.1.6 with mvn 3.3.9
Preferences -> Build,Execution,Deployment -> Build Tools -> Maven -> Running Tests
For IntelliJ 2019 and above
Settings-> Build,Execution,Deployment -> Build Tools -> Maven -> Running Tests
Uncheck argLine
I was able to fix this error in Netbeans by changing the surefire-plugin version to 2.10 and removing
<argLine>-Xmx1024m -XX:MaxPermSize=256m ${argLine}</argLine>
from the maven-surefire-plugin configuration. Instead i have created a property argLine that is picked automatically by surefire.
<properties>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
</plugin>
Now, i can run and debug single files and test methods. And Code Coverage is working as expected.
Update of pom.xml solved my problem.
<argLine>${surefire.argLine}</argLine>
Complete plugin info in pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<parallel>classes</parallel>
<threadCount>10</threadCount>
<workingDirectory>${project.build.directory}</workingDirectory>
<jvm>${env.JDK1_8_HOME}\bin\java</jvm>
<argLine>${surefire.argLine}</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>2.18.1</version>
</dependency>
</dependencies>
</plugin> -->
Was looking for this and found this project "fix" it in this thread
Basically define your jacocoArgLine var name as empty project property. Then in surefire configuration use #{jacocoArgLine} instead of dollar prefix.
I found out that I have to run my test case from maven with
mvn -Dtest=TestCircle test
not directly from IDE.
For a more permanent fix for every new project add the following to your IntelliJ IDEA Custom VM Options:
Help > Edit Custom VM options
Add: -Didea.maven.surefire.disable.argLine=true
This will deactivate surefire for all new projects you open.

jaxb2 maven plugin and configuration inside execution tag

I try to use JAXB2 maven plugin to generate java code from a bunch of .xsd files. If I try to generate from all xsds in a single execution I'll get org.xml.sax.SAXParseException: 'root' is already defined. I cannot modify the xsd files so I need to generate each independently. I found the following pom configuration to achieve that:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>jaxb-Execution1</id>
<phase>generate-sources</phase>
<goals><goal>xjc</goal></goals>
<configuration>
<schemaDirectory>${jaxbSchemaDirectory}</schemaDirectory>
<outputDirectory>${jaxbGenerateDirectory}</outputDirectory>
<staleFile>${jaxbGenerateDirectory}/.staleFlagExecution1</staleFile>
<bindingDirectory>${jaxbSchemaDirectory}</bindingDirectory>
<bindingFiles>bindings1.xml</bindingFiles>
<schemaFiles>schema1.xsd</schemaFiles>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
<execution>
<id>jaxb-Execution2</id>
<phase>generate-sources</phase>
<goals><goal>xjc</goal></goals>
<configuration>
<schemaDirectory>${jaxbSchemaDirectory}</schemaDirectory>
<outputDirectory>${jaxbGenerateDirectory}</outputDirectory>
<staleFile>${jaxbGenerateDirectory}/.staleFlagExecution2</staleFile>
<bindingDirectory>${jaxbSchemaDirectory}</bindingDirectory>
<bindingFiles>bindings2.xml</bindingFiles>
<schemaFiles>schema2.xsd</schemaFiles>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
</executions>
But this is not working. The problem is that configurations are not read from inside of the execution block. Why is that? I am using maven 2.2.1.
I had the same issue when I tried to run the plugin using:
mvn jaxb2:xjc
A workaround for me was using:
mvn generate-sources