Openshift 3 WAR - maven

In the Openshift 2 I had such a profile in a pom.xml file:
<profile>
<!-- openshift red hat cloud build profile -->
<id>openshift</id>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<outputDirectory>webapps</outputDirectory>
<warName>${project.artifactId}</warName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
and this was responsible for putting a WAR file to directory from where it was automatically deployed to Tomcat-like-jboss.
Now - in Openshift 3 - by using browser-embeded ssh console I checked that WAR files were build and put into /tmp/src/webapps directory. Where should I move it (how should I modify the Maven profile) to make new Openshift 3 Tomcat-like-jboss deploy it and host it?

I've found the answear - the correct outputDirectory is target, so the WAR plugin looks now:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<outputDirectory>target</outputDirectory>
<warName>ROOT</warName>
</configuration>
</plugin>
I've found it there: https://github.com/gshipley/book-helloworld/blob/master/pom.xml - in a sample OpenShift app. Now my WAR are being deployed to the WildFly!
Moreover - this free e-book is really heplful: https://www.openshift.com/promotions/for-developers.html.

Related

Running Selenium(TestNG) tests from Azure Devops

I'm working on running my automation test scripts (which is a Maven project
based on java and using test ng ) in AzureDevops CI/CD pipeline. I have pushed all my code to Github and created a Maven task to run the tests.
But when I try to run the Maven task , it is not considering testng.xml, where I have all the tests configurations like which tests to be run(order of the tests) and other configuration stuff like listener to create some custom reports. It is just running all the test classes present in my complete Maven project.
Please help me which config / task I should in add in my build inorder for the test to run based on my testng.xml
Below is the Pom.xml
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
TestAutomation
Test
0.0.1-SNAPSHOT
jar
Test
http://maven.apache.org
org.seleniumhq.selenium
selenium-java
3.14.0
org.testng
testng
6.11
compile
org.apache.poi
poi
3.16-beta2
com.relevantcodes
extentreports
2.41.2
commons-io
commons-io
2.6
log4j
log4j
1.2.17
com.googlecode.json-simple
json-simple
1.1.1
<!-- for gson https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<properties>
<property>
<name>listener</name>
<value>com.qa.ExtentReportListner.ExtentRerportListener</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>

Jenkins SonarQube plugin Multi Module Code Coverage Not Displaying

so we have a Spring Boot maven based project, which we split into multi modules which all works perfectly fine in unit tests and Jenkins, but coverage is not showing up in Sonar at all.
This is the structure of our application:
ApplicationRoot
-SharedCommonModule
--main
---java
-----com...(SomeModule.java)
--test
----com....(SomeModuleTest.java)
-ApplicationModule
--main
---java
-----com...(Application.java)
--test
----com....(ApplicationTest.java)
Parent pom file config:
<properties>
<!-- Sonar -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
<sonar.language>java</sonar.language>
<jacoco.destFile>${sonar.jacoco.reportPath}</jacoco.destFile>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<id>agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
SharedCommonModule pom:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
Main ApplicationModule pom file:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.org.Application</mainClass>
</configuration>
</plugin>
</plugins>
</build>
Jenkins SonarQube plugin configuration:
sonar.projectKey=com.Application
sonar.projectName=ApplicationModule
sonar.projectVersion=1.0.0.${BUILD_NUMBER}
sonar.sources=src/main
sonar.tests=src/test
sonar.java.binaries=target/classes
sonar.jacoco.reportPaths=target/jacoco.exec
sonar.modules=ApplicationModule,SharedCommonModule
ApplicationModule.sonar.projectName=ApplicationModule
SharedCommonModule.sonar.projectName=SharedCommonModule
We have researched and tried to hack it together from multiple examples, but nothing seems to work - closest we've got, is for Sonar to show some coverage, while some classes would show 0% coverage even though we know for sure we have UTs that used those classes (tested via IntelliJ).
So, without without the added properties and build xml sections above, we get partial coverage, only for ApplicaitonModule, I think all reported uncovered classes, belong to SharedCommonModule
EDIT: I want to clarify, the combined jacoco.exec file does show coverage for classes when loaded in IntelliJ Coverage tool, but Sonar does not show coverage for the very same classes in its report (which is generated only when I remove the build and properties xml elements in the parent pom).
Please help :)
You have Maven projects, so you should start using Sonar Scanner for Maven.
It is smart enough to generate all parameters for you.
If you remove:
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
<jacoco.destFile>${sonar.jacoco.reportPath}</jacoco.destFile>
<destFile>${sonar.jacoco.reportPath}</destFile>
Jenkins SonarQube plugin configuration
add to parent pom file:
<name>ApplicationModule</name>
<properties>
<sonar.sources>src/main</sonar.sources>
<sonar.tests>src/test</sonar.tests>
<sonar.projectKey>com.Application</sonar.projectKey>
</properties>
add to SharedCommonModule pom file:
<name>SharedCommonModule</name>
add to ApplicationModule.pom file:
<name>ApplicationModule</name>
and finally execute:
mvn sonar:sonar -Dsonar.projectVersion="1.0.0.${BUILD_NUMBER}"
After that you should see missing coverage data.
Btw. it is not recomended to set sonar.projectKey for Maven projects. I set it to the same value, so your project will be accessible under the same link.

mvn war:war without copying resources

I have a file in a Maven project that need to be obsfuscated. At the moment I:
Clean/build the project;
Open an eternal application to obsfuscate the file in the /target/ROOT/blah folder;
I then want to run mvn war:war but it always copies the resources folder back into the /target/ROOT folder which overwrites the obsfuscated file.
MVN output
Packaging webapp
Assembling webapp [core] in [core\target\ROOT]
Processing war project
Copying webapp resources [src\main\webapp] <= I THINK THIS IS THE PROBLEM
Webapp assembled in [22812 msecs]
Building war: target\ROOT.war
I have tried the following and a few variations:
<profile>
<id>war-only</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceExcludes>**</warSourceExcludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Any suggestions please?
OK got it eventually:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>${basedir}/src/main/null</warSourceDirectory>
</configuration>
</plugin>
Setting warSourceDirectory to any non-existant directory meant it didn't copy anything in.

Deploy Java EE Wildfly REST Application to Openshift

I am new to Openshift and having trouble with deploying my Java EE project to it. I have made REST API for a simple webstore. Locally it works fine on Wildfly 9.0.2 I want to deploy it on openshift. I 've made new wildfly9 + mysql5.5 application using eclipse openshit jboss plugin and added a profile to root pom.xml:
<profiles>
<profile>
<id>openshift</id>
<build>
<finalName>webstore</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<outputDirectory>deployments</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
My root project consist of several maven modules including store-ear (EAR), store-jpa (JAR), store-rest (WAR), store-web (WAR), store-services (EJB), store-rest-interfaces (JAR),store-service-interfaces (JAR).
I have changed datasourse in JPA configuration (persistence.xml) to use MysqlDB on Openshift.
After pushing back to openshift the build is succesfull, but when it gets deployed it is missing some dependancies (ClassNotFoundException), and fails to deploy main war file.
You use a maven-war plugin in your openshift maven profile.
But you say that your project is packaged as en ear. So you should probably deploy this ear which contains all your project modules (wars, ejbs, libs...) instead of a specific war of your project.
To achieve this, you have to use a maven-ear plugin instead of the maven-war one in your openshift profile which would look like this:
<profile>
<id>openshift</id>
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10</version>
<configuration>
<outputDirectory>deployments</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>

How to deploy Spring Boot application to different URL on Tomcat?

I am building and deploying my Spring Boot application into Tomcat with mvn tomcat:deploy and with this configuration:
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://127.0.0.1:8080/manager/text</url>
<server>tomcat</server>
<path>/${project.build.finalName}</path>
<username>admin</username>
<password>password</password>
</configuration>
</plugin>
</plugins>
</build>
Application runs then at /${project.artifactId}. I would like to deploy the application to the another URL, ideally to set target URL while I call Maven deploy command. Is it possible? If so, how can I achieve it?
You can override maven properties from command line with -D option.
To specify another url for your app the interesting properties are maven.tomcat.port and maven.tomcat.path.
The following command line should do the trick :
mvn -Dmaven.tomcat.port=8181 -Dmaven.tomcat.path=/custom tomcat:deploy

Resources