unable to convert my maven to eclipse - maven-3

Please, I am new to maven and trying to build my first maven project. So, here are a few things I did:
from my command line into a directory called MavenProject I created:
mvn archetype:generate
and then choose a number to apply number, I entered 15 then;
Choose com.dyuproject.protostuff.archetype:basic-webapp version:
I chose version 1.0.7
groupId: com.henry
artifactId: HibernateTest
and the rest, I just entered..
and the project was created but then I typed in mvn eclipse:eclipse, I got an error that there was no pom.xml file even though I can see there is one in my mavenProject. so, I changed into the HibernateTest directory and in that directory, I tried the mvn eclipse:eclipse command again but this time, it gave the eorror:
Plugin com.dyuproject.protostuff:protostuff-maven-plugin:1.0.2-SNAPSHOT or one of its
dependencies could not be resolved: Failed to read artifact descriptor for
com.dyuproject.protostuff:protostuff-maven-plugin:jar:1.0.2-SNAPSHOT: Could not find artifact
com.dyuproject.protostuff:protostuff-maven-plugin:pom:1.0.2-SNAPSHOT
I tried to solve this by going to mvnrepository.com and found the protostuff maven and added the dependencies but still couldn't solve it. here is my pom.xml file:
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLS$
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_$
<parent>
<artifactId>Hibernate</artifactId>
<groupId>com.henry</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.henry</groupId>
<artifactId>Hibernate-model</artifactId>
<name>Hibernate :: model</name>
<packaging>jar</packaging>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-maven-plugin</artifactId>
<version>${protostuff.version}</version>
<configuration>
<protoModules>
<protoModule>
<source>src/main/resources/com/henry/model/model.proto</source>
<outputDir>src/main/java</outputDir>
<output>java_bean</output>
<encoding>UTF-8</encoding>
<options>
<property>
<name>generate_field_map</name>
</property>
<property>
<name>separate_schema</name>
</property>
<property>
<name>builder_pattern</name>
</property>
<property>
<name>generate_helper_methods</name>
</property>
</options>
</protoModule>
</protoModules>
</configuration>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-core</artifactId>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-maven-plugin</artifactId>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-codegen</artifactId>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-core</artifactId>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-maven-plugin</artifactId>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-codegen</artifactId>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-compiler</artifactId>
<version>1.0.7</version>
</dependency>
</dependencies>
</project>
Any help will be appreciated. Sorry am a newbie :)

First try to build the project on the command line: mvn install. That should succeed.
But it looks like it won't, as it is looking for a SNAPSHOT dependency version of ${protostuff.version}. When I look in the Maven central repository, there's really only release versions (as it should be). Somehow you have to fix that, probably in your parent project.
The POM file should be in the root of the project and called pom.xml. Where you find the POM file called pom.xml is the root of the project :)
Only use eclipse:eclipse as a last resort. If you have free choice of Eclipse, and you have no wizardry in your Maven projects, you should be able to use the m2e (m2eclipse) Eclipse plugin.
That's an Eclipse plugin, not a Maven plugin, so no additional steps are needed on the command line. Just go into Eclipse, make sure the m2e plugin is installed. Then import your project (Import, "Existing Maven Projects").
All the files that Eclipse needs for its own bookkeeping should be created upon import and be based on the POM file. I.e. .classpath, .project and .settings (folder). If you have any of those prior to importing into Eclipse, you may be better off removing them (they may be remnants of your eclipse:eclipse attempts.

Related

Unable to find artifact from artifactory

I am using JFrog artifactory 3.2.1.1 with Maven 3.2.1.
I uploaded a built project that exists in libs-snapshot-local under the repository browser. If I browse to com.foo.project, I will see the project-1.0-20151113.133436-1.jar file and pom and metadata in the artifactory browser.
Even accessing http://example.com:8081/artifactory/webapp/browserepo.html?42&pathId=libs-snapshot-local:com/foo/project/1.0-SNAPSHOT/project-1.0-20151113.133436-1.jar shows me the jar file inside.
I used the settings.xml generator from the artifactory to generate the <repository> tag that I use in the following 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.foo.bar</groupId>
<artifactId>exampleApp</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>exampleApp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<snapshots />
<id>snapshots</id>
<name>libs-snapshot</name>
<url>http://example.foo:8081/artifactory/libs-snapshot</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.foo</groupId>
<artifactId>project</artifactId>
<version>1.0</version>
<type>jar</type>
<includes>myFolder</includes>
<outputDirectory>${project.build.directory}/newFolder/js/gmoketest</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I just get:
Failed to execute goal
org.apache.maven.plugins:maven-dependency-plugin:2.8:unpack (unpack)
on project exampleApp: Unable to find artifact. Failure to find
com.foo:project:jar:1.0 in
http://example.com:8081/artifactory/libs-snapshot was cached in the
local repository, resolution will not be reattempted until the update
interval of snapshots has elapsed or updates are forced
And if I change
http://example.foo:8081/artifactory/libs-snapshot
to
http://example.foo:8081/artifactory/libs-snapshot-local
Then I get:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-dependency-plugin:2.8:unpack (unpack)
on project exampleApp: Unable to resolve artifact. Could not transfer
artifact com.foo:project:jar:1.0 from/to snapshots
(http://example.com:8081/artifactory/libs-snapshot-local): Failed to
transfer file:
http://example.com:8081/artifactory/libs-snapshot-local/com/foo/project/1.0/project-1.0.jar.
Return code is: 409 , ReasonPhrase:Conflict.
I will keep deploying new snapshots now and then to the same project-1.0 and would like this pom file to just include the latest SNAPSHOT build when building from the artifactory.
The answer was, as I quickly figured out that the version needs to be specified as:
<version>1.0-SNAPSHOT</version>

Parent POM is taking the same version which I am giving in the module version

I have a multi module maven project for e.g.
A
B
C
D
E
Currently this project is working fine and have a single job to build all the modules and upload to the artifactory with some version for e.g. 4.0.0-.They are using versions:set -DnewVersion=4.0.0-${BUILD_NUMBER} from Jenkins job.Now my next task is to split this project into module so they dev team can build each module independetly but my issue is some modules is having the dependecy on other modules for e.g
Module B is having dependecy on module A and Module C.if I build the module A first then it generate the number 4.0.0-00001 and upload it to the artifactory and then I build the module C then it generate the build 4.0.0-00005.Now the question comes how could I build the module B which is having the dependency on module A and C.In my opinion I need to define the version of module A and C explicitly in the dependency section.
<dependency>
<groupId>com.xyz.engine</groupId>
<artifactId>A</artifactId>
<version>4.0.0-00005</version>
</dependency>
From my module POM I am calling my parent POM and In jenkins job I am giving
versions:set -DnewVersion=4.0.0-${BUILD_NUMBER} for versioning purpose if I explicity define the version of A module then it is also passing the same value to the Parent POM and searching for it which is not avilable.Below is my module POM file
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.truvenhealth.analyticsengine</groupId>
<artifactId>AnalyticsEngine</artifactId>
<version>4.0.0-00002</version>
</parent>
<artifactId>LicenseVerifier</artifactId>
<name>LicenseVerifier</name>
<packaging>jar</packaging>
<dependencies>
<!-- Modules dependencies -->
<dependency>
<groupId>com.xyz.engine</groupId>
<artifactId>Common</artifactId>
<version>4.0.0-00007</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
</dependency>
<!-- External dependencies -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>com.verhas</groupId>
<artifactId>license3j</artifactId>
<version>1.0.4</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<!-- Plugin configurations inherited from the parent POM -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
it is taking the same value for Parent POM which I assigned to Common module .I am keeping the Parent POM in separate repository it should not take the same value it should only take that value which I am defining for the Parent POM and it should download it from their and provide all the values to module POM and the build should be created for module LicenseVerifier with different version.
If you have a multi module build which looks like this:
root (pom.xml parent of all modules)
+---- module-a (pom.xml)
+---- module-b (pom.xml)
+---- module-c (pom.xml)
+---- module-d (pom.xml)
To build a module separately you can do this via Maven like this:
mvn -pl module-a clean package
This will build the module-a only and get the dependencies of other modules from the remote repository. Or you can enhance that like this:
mvn -pl module-a -amd clean package
where the option -amd means --also-make-dependents. If a developer needs a particular state you can do this by a mvn install first and afterwards only build the module you would like to build.
A very important thing in relationship with multi module builds is to have the same version for all modules and the parent. So dependencies between those modules is no problem.
Starting with Maven 3.2.1 you can define the version via properties.
A simple change to prevent Maven from emitting warnings about versions
with property expressions. Allowed property expressions in versions
include ${revision}, ${changelist}, and ${sha1}. These properties can
be set externally, but eventually a mechanism will be created in Maven
where these properties can be injected in a standard way. For example
you may want to glean the current Git revision and inject that value
into ${sha1}. This is by no means a complete solution for continuous
delivery but is a step in the right direction.
Furthermore during development i would prefer the SNAPSHOT versions which the cleanup in the repository manager simpler. So in essence i don't any need to separate the modules which logicaly belong together.
Apart from that if you use the same version within your multimodule build you can use things like this: ${project.version} to define the version of a dependency which is part of the reactor.

possible bug in Maven + plexus + eclipse compiler on case sensitive packages?

I encounter a very strange problem with Maven and Eclipse compiler.
While in Eclipse+m2eclipse, I have no problem compiling a small project (archetype quick start) with the following single class.
package test.test;
import com.Ostermiller.util.CSVParser;
public class TestCaseSensitive {
CSVParser csvParser;
}
Ostermiller utils is added to pom.xml. Eclipse Kepler compiles the project.
Next, mvn compile works out-of-the-box.
Now the issue, I switch to compiler 3.1 and asks for Eclipse compiler (to be able to handle same compilation issues in console mode as well as IDE mode). This is the POM :
<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>test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>test</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ostermiller</groupId>
<artifactId>utils</artifactId>
<version>1.07.00</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerId>eclipse</compilerId>
<source>1.7</source>
<target>1.7</target>
<optimize>true</optimize>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
<fork>false</fork>
<compilerArgument>-err:nullAnnot,null</compilerArgument>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
And now here is the result :
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project test: Compilation failure: Compilation failure:
[ERROR] /home/me/workspaces/4/3/ws/test/src/main/java/test/test/TestCaseSensitive.java:[3] The import com.Ostermiller cannot be resolved
[ERROR] /home/me/workspaces/4/3/ws/test/src/main/java/test/test/TestCaseSensitive.java:[7] CSVParser cannot be resolved to a type
The package com.Ostermiller exists (it compiles in maven default compiler as well in Eclipse IDE), but not after switching to eclipse compiler.
Please note that the reported error path is also wrong :
[ERROR] /home/me/workspaces/4/3/ws/test/src/main/java/...
should be
[ERROR] /home/me/workspaces/4.3/ws/test/src/main/java/...
Has someone an idea? Where shall the potential bug be reported?
Have you tried using the jdt compiler provided by tycho?
See http://wiki.eclipse.org/Tycho/FAQ#Can_I_use_the_Tycho_compiler_support_in_non-OSGi_projects.2C_too.3F
That'd give you :
<plugin>
<!-- Use compiler plugin with tycho as the adapter to the JDT compiler. -->
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerId>jdt</compilerId>
<source>1.7</source>
<target>1.7</target>
<optimize>true</optimize>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
<fork>false</fork>
<compilerArgument>-err:nullAnnot,null</compilerArgument>
</configuration>
<dependencies>
<!-- This dependency provides the implementation of compiler "jdt": -->
<dependency>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-jdt</artifactId>
<version>${tycho-version}</version>
</dependency>
</dependencies>
</plugin>
Currently tycho-version=0.18.0

maven dependency:copy across modules

Have a project with several module projects and itself having other module projects. I have certain modules generating a special artifact type '.kar', and I am deploying this to artifactory during maven deploy phase.
Now I want to find a way by using this existing pom to download these specific artifacts from artifactory by version.
mvn dependency:copy <> allows me to download this per specific artifact.
I want this to be done via the pom file which generates these artifacts. Problem is when I use the dependency:copy, it only runs on the current pom which may or may not have the special artifact.
If I use it in then it re-deploys all the artifacts and downloads the special artifact correctly. This is not right solution though.
You could add a new module to your project that has <dependencies> to all of your .kar artifacts. In the POM file of this new module you can use the copy-dependencies goal of the maven-dependency-plugin.
<project>
<!-- Integrate this module into your multi-module project. -->
<parent>
<groupId>my.group.id</groupId>
<artifactId>my-parent-pom</artifactId>
<version>1.0.0-SNAPSHOT</version<
</parent>
...
<!-- Add dependencies for all your .kar artifacts. -->
<dependencies>
<dependency>
<groupId>my.group.id</groupId>
<artifactId>kar-artifact-1</artifactId>
<version>${project.version}</version>
<type>kar</type>
</dependency>
<dependency>
<groupId>my.group.id</groupId>
<artifactId>kar-artifact-2</artifactId>
<version>${project.version}</version>
<type>kar</type>
</dependency>
...
</dependencies>
<build>
<plugins>
<!-- Use the maven-dependency-plugin to copy your .kar artifacts. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy-kar-artifacts</id>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeTypes>kar</includeTypes>
</configuration>
</execution>
</executions>
<plugin>
</plugins>
</build>
</project>

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)

Resources