Maven to SVN repository - maven-3

I am trying to connect maven to SVN repository using valid credentials. My pom.xml file is as follows,
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.maven.myfirstproject</groupId>
<artifactId>myfirstproject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<scm>
<connection>scm:svn:http://d-113017553/svn/PRONTO/trunk/dev</connection>
<developerConnection>scm:svn:http://d-113017553/svn/PRONTO/trunk/dev</developerConnection>
</scm>
<servers>
<id>central</id>
<username>keerthana</username>
<password>keerthana</password>
<url>http://d-113017553/svn/PRONTO/trunk/dev</url>
</servers>
<plugin>
<groupid>org.apache.maven.plugins</groupid>
<artifactid>maven-scm-plugin</artifactid>
<version>1.8.1</version>
</plugin>
</build>
</project>
When i run it i get the following errors,
**1)coreException : could not calculate build plan: plugin org.apache.maven.plugins:maven-compiler:2.3.2 or one of its dependencies could not be resolved:Failed to read artifact descriptor for org.apache.maven.plugins:maven-compiler-plugin:jar:2.3.2
2)Plugin execution not covered by lifecycle configuration:org.apache.maven.plugins:maven-compiler-plugin:2.3.2:testCompile(execution:default-testCompile,phase:test-compile)**
Would anyone help me out to solve the above errors pls?????

First your pom.xml file can contain the information about VCS but you have to follow the schema for the pom.xml file which can get a good impression about here.
Furthermore it's good practice to indent XML file correctly like this:
<scm>
<connection>scm:svn:http://svn.server.com/svn/my-project/trunk</connection>
<developerConnection>scm:svn:https://svn.server.com/svn/my-project/trunk</developerConnection>
<url>http://svn.server.com/websvn/my-project</url>
</scm>
Apart from the above the things like this:
<servers>
<id>central</id>
<username>keerthana</username>
<password>keerthana</password>
<url>http://d-113017553/svn/PRONTO/trunk/dev</url>
</servers>
do not belong into the pom.xml. They should be put into the setting.xml file in your home folder (usually $HOME/.m2/settings.xml). And of course should you never put credentials into your pom file.

Related

Maven Glassfish plugin - Handling redeploy/deploy/undeploy Failure

I need to build and deploy the war into glassfish using maven(Problem explained below).
Currently I managed to deploy the war using maven glassfish plugin and I've used the goal redploy as shown in the POM below:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Myapp</groupId>
<artifactId>Myapp</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>APP WEB APP</name>
<url>http://maven.apache.org</url>
<build>
<finalName>MyApp</finalName>
<plugins>
<plugin>
<groupId>org.glassfish.maven.plugin</groupId>
<artifactId>maven-glassfish-plugin</artifactId>
<configuration>
<terse>false</terse>
<echo>true</echo>
<debug>true</debug>
<glassfishDirectory>C:\glassfish3\glassfish</glassfishDirectory>
<user>admin</user>
<adminPassword>admin</adminPassword>
<domain>
<name>domain1</name>
<host>localhost</host>
<adminPort>4848</adminPort>
</domain>
<components>
<component>
<name>${project.artifactId}</name>
<artifact>${project.build.directory}/${project.build.finalName}.war</artifact>
</component>
</components>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>redeploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Problem: say there is already a war deployed and when I execute the command mvn clean install and something goes wrong during the deployment.Since I've used the goal as redeploy the war would 1st do a undeploy and then do a deploy.In my case this POM cannot be used for the next time because there is a failure and the war does not exist.
Help required
Please help me to achieve a check in POM whether the war is deployed or not and then based on the result I need to initiate goals deploy or undeploy which suites.
Say there is no war deployed i need to call glassfish:deploy in POM.
Thanks for your time in advance
Found my answer Here:
Redeploy remote glassfish with cargo fails
No matter there is or isn't a war deployed the cargo plugin takes care of the above mentioned problem.
Main Catch is adding
<cargo.runtime.args>force=true</cargo.runtime.args>

Fortify + maven exclude xsd files

I have an issue with running scan with excluding xsd files in fortify SCA.
I am using maven (with fortify plugin) + jenkins.
My POM.xml used by Jenkins:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pl.bluecode</groupId>
<artifactId>bc</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<properties>
</properties>
<scm>
<connection>scm:svn:https://subversion......</connection>
<developerConnection>scm:svn:https://subversion.....</developerConnection>
<tag>HEAD</tag>
<url>https://subversion......</url>
</scm>
<profiles>
<profile>
<id>common</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>!skipCommonProfile</name>
</property>
</activation>
<modules>
<module>Project1</module>
<module>Project2</module>
</modules>
</profile>
<profile>
<id>profile1</id>
<modules>
<module>Project3</module>
<module>Project4</module>
</modules>
</profile>
</profiles>
<build>
<sourceDirectory>${basedir}/src</sourceDirectory>
<finalName>${project.artifactId}</finalName>
<resources>
<resource>
<directory>${basedir}/src</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src</directory>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.fortify.ps.maven.plugin</groupId>
<artifactId>maven-sca-plugin</artifactId>
<version>2.6</version>
<configuration>
<source>1.5</source>
<failOnSCAError>true</failOnSCAError>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
My Jenkins Maven goals looks like:
1st goal:
com.fortify.ps.maven.plugin:maven-sca-plugin:2.6:clean -Pprofile1
2nd goal:
com.fortify.ps.maven.plugin:maven-sca-plugin:2.6:translate -Pprofile1
3rd goal:
com.fortify.ps.maven.plugin:maven-sca-plugin:2.6:scan -Pprofile1
Unfortunately I can not attach image.
Above configuration is working as expected till now.
Now, I'd like to exclude all XSD files from scan.
How to do it?
I tried to add -exclude ".xsd" entry in maven goals:
com.fortify.ps.maven.plugin:maven-sca-plugin:2.6:scan -Pprofile -exclude ".xsd"
but it doesn't work.
If someone can help we I would be grateful.
Thanks.
in theory the Fortify Maven Plugin supports the exclusion of files, but it doesn't always work as expected.
Now, that being said, you are not invoking the exclusion correctly. Where you built the Fortify Maven Plugin, find the documentation for the translate goal, e.g. for me: /Samples/advanced/maven-plugin/target/site/translate-mojo.html#exclude.
There you can find the correct way to invoke exclusion. On the command line:
"-Dfortify.sca.exclude=*.xsd"
or in the POM (if you set up the fortify translate job there)
<exclude>
*.xsd
</exclude>
Now back to my first point. Sometimes exclusion is more difficult to effect than just by setting the value as *.extension. You may also need to specify the directory as well, so if the above doesn't work, try also the Fortify special glob parameter "**" which means any recursive subdirectory match. To wit:
"-Dfortify.sca.exclude=**/*.xsd"
or
<exclude>
**/*.xsd
</exclude>
If neither of the above work, then contact Fortify Technical Support.
Pro tip: you can also set this value in Core/config/fortify-sca.properties, where it will affect every invocation of sourceanalyzer on the system. That includes invocations via the maven plugin.

In multimodule maven project, how to execute proper goal for each module?

I have three maven projects in my prototype:
bookman (main project)
|-- bookman-back-lend (module, simple service app)
\-- bookman-front-web (module, simple web app)
This is very simple example book lending app (for library or something) to learn various technologies and all of that.
Problem is that I can't make parent pom to execute goals in module poms.
Calling mvn clean package wildfly:deploy in any module individually works without problem. It compiles, deploys, war is replaced, Wildfly 8 does its thing, etc. But if I call parent POM with mvn clean package (I'm not even sure what to call...), it doesn't do much - certainly it does not deploy to wildfly any of modules. Wildfly does not budge. In parent POM, calling mvn clean package wildfly:deploy does not work, of course.
Here is parent pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.mader.bookman</groupId>
<artifactId>bookman</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Main BookMan superproject.</name>
<description>Main BookMan superproject.</description>
<modules>
<module>bookman-front-web</module>
<module>bookman-back-lend</module>
</modules>
</project>
And module POMs, with some stuff cut out for brevity (I assume they aren't related to my problem).
bookman-front-web/pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>bookman-front-web</artifactId>
<packaging>war</packaging>
<name>Frontend project - webpage.</name>
<description>Web page to handle lending books.</description>
<parent>
<groupId>org.mader.bookman</groupId>
<artifactId>bookman</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<properties>
...
</properties>
<repositories>
...
</repositories>
<dependencyManagement>
...
</dependencyManagement>
<dependencies>
...
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<defaultGoal>clean package wildfly:deploy</defaultGoal>
<plugins>
<plugin> <!-- To use, run: mvn clean package wildfly:deploy -->
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${version.wildfly.maven.plugin}</version>
</plugin>
</plugins>
</build>
</project>
And bookman-back-lend/pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>bookman-back-lend</artifactId>
<packaging>war</packaging>
<name>Backend project - lending.</name>
<description>Business logic to handle books, users and act of lending.</description>
<parent>
<groupId>org.mader.bookman</groupId>
<artifactId>bookman</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<properties>
...
</properties>
<repositories>
...
</repositories>
<dependencyManagement>
...
</dependencyManagement>
<dependencies>
...
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<defaultGoal>clean package wildfly:deploy</defaultGoal>
<plugins>
<plugin> <!-- To use, run: mvn clean package wildfly:deploy -->
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${version.wildfly.maven.plugin}</version>
</plugin>
</plugins>
</build>
</project>
It should be possible to have customized goals to execute for each module individually, right? Right? Otherwise those aggregate POMs are rather useless.
Unfortunately, questions like this suggest that maven goal executed on parent POM is exactly same goal to execute on child POMs. Who thinks up something like that? What if I need completely different goals in each child module?
All answers I found are few years old, maybe... just maybe... sanity prevailed and maven now allows something like that? After all, all information neccessary to do this should be accessible, like defaultGoal tag.
Problem was solved in radical way. Maven is dead, long live Gradle.
I was tinkering with it last few days and I already moved prototype to point where it actually works. While there is still tons of work left, I already know I will not be looking back.
So, yeah... if you have requirements that cannot be done easily or at all with Maven for various reasons, then consider Gradle. In fact, consider Gradle anyway.

Sonar and MAVEN POM file with Dependencies

I have setup Maven and Sonar to analyze .NET projects and it works fine for winforms projects. However when I add an MVC project it gives a build Failure because it can't find the System.Web.MVC.dll file. I have an Fx-Cop plugin that runs as part of Sonar.
One way to get around this would be to package the dll, copy local= true with the project. However I dont want to do that(any thing wrong with packaging the MVC file along?)
How do I add a dependency to the MVC dll? I followed this example and added it like this:
<dependencies>
<dependency>
<groupId>artifact_group_id</groupId>
<artifactId>System.WEb.MVC</artifactId>
<version>4.0.30319</version>
<type>library</type>
<scope>system</scope>
<systemPath>C:\DOTNET\DLLS\System.Web.Mvc.dll</systemPath>
</dependency>
</dependencies>
Still I get a Build Failure caused by FX-Cop. Looking at the FX-Cop logs I get a message as below:
The following error was encountered while reading module 'MyTestMvcApp': Assembly reference cannot be resolved: System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
I'm using apache-maven-3.0.2 and sonar-3.2. Can anyone help with this?
This is the full POM.XML file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Test</groupId>
<artifactId>Sonar.For.NET.Test</artifactId>
<version>1.0</version>
<name>Testing </name>
<packaging>netpack</packaging>
<properties>
<visual.studio.solution>TestProjectsForSonarBuild.sln</visual.studio.solution>
<visual.test.project.pattern>*.Tests;*Test</visual.test.project.pattern>
<dotnet.tool.version>4.0</dotnet.tool.version>
<sonar.language>cs</sonar.language>
</properties>
<dependencies>
<dependency>
<groupId>artifact_group_id</groupId>
<artifactId>System.WEb.MVC</artifactId>
<version>4.0.30319</version>
<type>library</type>
<scope>system</scope>
<systemPath>C:\DOTNET\DLLS\System.Web.Mvc.dll</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.sonar-plugins.dotnet</groupId>
<artifactId>maven-dotnet-plugin</artifactId>
<version>0.6</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<configuration>
<toolVersion>3.5</toolVersion>
<buildConfigurations>Debug</buildConfigurations>
<rebuild>true</rebuild>
<language>cs</language>
</configuration>
</plugin>
</plugins>
</build>
</project>
Thanks for your time.
You can use the "sonar.fxcop.assemblyDependencyDirectories" property as described on the documentation page for the FxCop plugin.
So you have 2 solutions from there:
either your build process copies "System.Web.MVC.dll" in a temp folder, which you reference through the this property
or you directly reference an absolute path where this DLL can be found (but your property may then be not portable accros different environments/servers)

how to copy 3rd party jars in WEB-INF/lib of war

I have created dynamic web project in eclipse.I have developed some code which requires
dependeny jars mentioned in POM as well as some 3rd party jars;so i added all jars in the
build path of the project.these jars are required to compile and run the code when we
deploy in the tomcat.
below pom.xml is used to build the war.I want to include these 3rd party jars in WEB-
INF/lib folder in the war.what changes do i need to make in pom so these jars will come in WEB-INF/lib folder?
Is there any way like whatever jars are added in the project build path does comes in WEB-
INF/lib folder.
or else
put all 3rd party jars in temp folder.then using copy command can we copy these jars from
this temp folder to WEB-INF/lib folder.what is the best approach?
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sample</groupId>
<artifactId>SampleWS</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Simple CXF project using spring configuration</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>
If you just want to add 3rd party jars in WEB-INF/lib folder, no changes needs to be made to POM.xml. Just do the following Project > Properties > Java Build Path > Libraries > Click on Add JARs....locate JARs in your you project's lib folder.. Now these JARs will be added to war along with those in POM.xml.
P.S: Personally i won't recommend to add jars partially from POM and partially from lib folder.

Resources