Setting VM argument via pom.xml - java

I need to set -Duser.language via pom.xml since I need language specific database queries.
When I pass -Duser.language=tr to VM options upon running spring boot application on Intellij, it works. But I need this to be done in pom.xml for profiling.
Below ways are not working. Language is not set.
<profile>
<properties>
<argLine>-Duser.language=tr -Duser.region=TR</argLine>
</properties>
...
</profile>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<verbose>true</verbose>
<fork>true</fork>
<compilerArgs>
<arg>-J-Duser.language=tr_TR</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<argLine>-Duser.language=tr -Duser.region=TR</argLine>
<systemPropertyVariables>
<user.language>tr</user.language>
<user.region>TR</user.region>
</systemPropertyVariables>
</configuration>
</plugin>
Only this is working but I need to run application with mvn spring-boot:run for this to work and that is not an option.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>
-Duser.language=tr
</jvmArguments>
</configuration>
...
</plugin>
How can I pass vm arguments via pom.xml?

Related

Why no test is run when execute mvn test -P{profile Id}

I have defined my profiles in pom.xml as below:
<profiles>
<profile>
<id>Test123</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<!-- put your configurations here -->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/target/testdemo.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
And we I ran a command mvn test -PTest123, there is no Tests being run as shown as below:
cmd output
However, we I ran with command mvn test, it has ran the test as shown as below:
cmd output
After reviewing the output files I noticed that different versions of the maven-compiler-plugin and maven-surefire-plugin are running per profile. Is this project dependent on a parent pom.xml? Otherwise changing the versions on the plugins to:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<!-- put your configurations here -->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/target/testdemo.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
should fix the problem in case the versioning is not important.

maven surefire plugin is not executing runners in parallel

I have set up maven-surefire-plugin in POM.xml.
Ideally as per the help I got over the internet for using these plugin, my set up should run cucumber Runner files in parallel but they are always getting executed sequentially.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<fork>true</fork>
<executable>C:\Program Files\Java\jdk1.8.0_201\bin\javac.exe</executable>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<parallel>classes</parallel>
<forkMode>perthread</forkMode>
<threadCount>2</threadCount>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
<includes>
<include>**/*Runner.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

changing java source compiler in maven

I am using spring-boot-maven-plugin to maven compile my source code as I want maven dependency jars to be part of my jar. (suggested by someone). I have written code according to java 1.7 but maven compiler is trying to compile it with 1.5 (default for maven). To change it I defined source as 1.7 but it is still compiling it with 1.5 Here is my pom.xml example.
<build>
<sourceDirectory>src</sourceDirectory>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.2.RELEASE</version>
<configuration>
<finalName>BAU_Report</finalName>
<source>1.7</source>
<target>1.7</target>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.bau.report.MainClass</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
You should use maven compiler plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
Add this to build -> plugins section.
If you’re using the spring boot parent pom you can use this property shortcut instead in your pom.xml
<properties>
<java.version>7</java.version>
</properties>
Add org.apache.maven.plugins for the pom.xml file.
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</build>
Maven properties for the compiler version can be set as following.
Method 1
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Method 2
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>

Plain Selenium and Thucydides reports

I have plain seleneum ui tests and I want to have nice thucydides reports after how can I do this.
In maven pom.xml I have profile like this:
<profile>
<id>MobileTests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<argLine>-Dfile.encoding=UTF-8</argLine>
<argLine>-Dwebdriver.remote.url=http://192.168.1.5/wd/hub</argLine>
<groups>ru.testgroups.mobile.AllMobile</groups>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.0</version>
<configuration>
<reportPlugins>
<plugin>
<groupId>net.thucydides.maven.plugins</groupId>
<artifactId>maven-thucydides-plugin</artifactId>
<version>${thucydides.version}</version>
</plugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</build>
</profile>
It suppose to generate reports, but it does not. How can I get thucydides reports from plain selenium tests
You should add the serenity (or thucydides, if you're using an older version) as a reporting plugin:
<reporting>
<plugins>
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>${serenity.version}</version>
</plugin>
</plugins>
</reporting>

How to override configuration of maven-compiler-plugin. (build directory, I want to change by using profile)

I want to ignore some build errors at a specific directory by using maven's profile. I tried to do like below but it did not work. Any help will be appreciated?
============================================
[executed command]
mvn -P test clean compile
============================================
[part of pom.xml]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>test</id>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<excludes>
<exclude>**/nocompile/*</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
============================================
[a class happened a build error]
package com.sample.web.nocompile;
public class NoCompileSample {
// An error do happen here
private String
}
Your profile looks alright. There seems to be a known issue with the maven compiler though. See this answer to a similar question for a description of the problem and a workaround.

Categories

Resources