importing maven project with m2e ignores active profile - eclipse

I have defined a profile in my POM. Now I want to import this project with m2e. When I do so the default profile is ignored. On the other hand If I set the profile explicitly before import which profiles should be active (Import Maven Project > Advanced) then the project is imported with the correct profile.
Why is the profile is ignored when importing with m2e? If maven can determine the correct profile on command line why can't it do so with M2E?
<profiles>
<profile>
<id>important-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
... important stuff ...

Consider opening an issue at m2eclipse - Support because it is free software.

Related

Testing my code against two Eclipse releases with Tycho

I am in need to test my code against two target platforms (which can be wrong to start with, but I would like to keep the focus on the issue): Kepler and Luna.
To do this, I defined two repositories in my parent project:
<repositories>
<repository>
<id>kepler</id>
<layout>p2</layout>
<url>http://download.eclipse.org/releases/kepler</url>
</repository>
<repository>
<id>luna</id>
<layout>p2</layout>
<url>http://download.eclipse.org/releases/luna</url>
</repository>
</repositories>
Then I created two plugins, one for Kepler and one for Luna which declare two different dependencies (code is duplicated, but again this is a separate issue):
// Luna
Require-Bundle:
org.eclipse.e4.core.contexts;bundle-version="1.3.100"
// Kepler
Require-Bundle:
org.eclipse.e4.core.contexts;bundle-version="[1.3.0,1.3.100)"
Now, when I specify the adequate tycho.target-platform, through -D or settings.xml, and run the build with mvn clean install, one of these plugins always fails and the other one succeeds. Luna fails if I don't specify a Luna target, Kepler fails if I don't specify a Kepler target.
There must be a better way, I told myself, and I read about target-platform-configuration which I have configured with all the possible combinations of os/ws/arch.
But still it fails for one or the other. What am I doing wrong?
The problem is that you override your target platform configuration in the POM by using the deprecated -Dtycho.target-platform property. When that property is set, Tycho no longer uses the artifacts from the two p2 repositories that you have specified.
So, don't use this property (and also make sure that you don't set it your settings.xml) and your approach should work.
My answer came right after checking my ~/.m2/settings.xml:
<profile>
<id>tycho-kepler</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<tycho.targetPlatform>/usr/local/share/eclipse</tycho.targetPlatform>
</properties>
</profile>
<profile>
<id>tycho-luna</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<tycho.targetPlatform>/usr/local/share/eclipse-luna</tycho.targetPlatform>
</properties>
</profile>
Apparently these lines, even without having specified -P or the profile in the build, are added to the execution, something that I didn't now. Removing them solved the problem immediately.

Perforce+Sonar setup for New line code coverage

I am trying to find out code coverage on new lines only. I use jacoco report for IT coverage and run mvn sonar:sonar. Sonar does not display the new line code coverage.
I am not sure what configuration I am missing.It seems to work for svn repo. I run mvn sonar on the base version and again with the latest version.
I am using Perforce,SonarQube 4.4, SCM Activity Plugin 1.8.
Here is my POM.xml,
<scm>
<connection>scm:perforce:username#perforceserver:portnumber://depot</connection>
<developerConnection>scm:perforce:username#perforceserver:portnumber://depot</developerConnection>
<url>scm:perforce:username#perforceserver:portnumber://depot</url>
</scm>
<properties>
<skipTests>false</skipTests>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.jacoco.itReportPath>C:/SonarData/ExecFiles/CSMmergeddata.exec</sonar.jacoco.itReportPath>
<sonar.scm.reloadBlame>true</sonar.scm.reloadBlame>
<sonar.language>java</sonar.language>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>${acme-corporate-pom.sonarVersion}</version>
</plugin>
...
To have code coverage on new line information, SonarQube relies on information from the SCM engine. As you can see on the SCM Activity plugin matrix, Subversion is perfectly supported but not Perforce - which is only known to be tested by some users but not formally validated by SonarQube team as "supported".
So either:
your configuration of the SCM Activity plugin is not correct
See the "Additional configuration for Perforce" section of the documentation of this plugin
or you hit a bug in the implementation of the Maven SCM library (we know there are some bugs)
See all the open bugs on this lib

Using Maven's .m2/settings.xml throws warning in Eclipse m2e

I'm using Maven's settings.xml to override a property value for a log4j.properties file for development purposes. However, after I made this change, I now receive warnings in Eclipse m2e even though this is a normal use case:
Access "/Users/junger/.m2" directory outside of project base
directory.
(org.apache.maven.plugins:maven-resources-plugin:2.5:resources:default-resources:process-resources)
How do I remove this warning? Or, is there a bug tracking this? I couldn't find one.
In my pom.xml, I have -
<properties>
<log4j.properties.directory>src/main/java</log4j.properties.directory>
</properties>
In my settings.xml, I have -
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<log4j.properties.directory>/Users/junger/.m2/</log4j.properties.directory>
</properties>
</profile>
</profiles>
Looking at the code (the newScanner() method) of m2e, this seems to be an explicit warning when your project references files outside of its base directory.
For me, this warning is kind of justified. When you are referencing resources outside of your project's basedir, your builds might not be reproducible anymore. Your projects should rather be self contained without depending on external files.

Eclipse Maven runtime dependencies and profiles

Im trying to understand maven profiles and have run into the following issue.
This is my simplified example, I have two maven projects, project A and Project B.
project A has a compile time maven dependency on project B.
project B includes a runtime dependency (lets say to project C) when the maven profile "TEST" is active.
so the problem is the class path generated when I run project A. it doesn't have project C in it, even though the TEST profile is active for project A.
this is using eclipse Helios service release 1, Maven Integration for Eclipse plugin vrs 0.10.2.20100623-1649
any ideas?
I'm not sure that profiles are the best way to handle with TEST.
The use of profile to change dependecies will change the POM of the generated project.
If you install Project B with TEST activated, the runtime dependency will be added. (Whatever project A profile).
Optional dependencies are not added by transitivity. You need to add the dependency in project A.
I just tested this in Eclipse using m2eclipse 0.12.x. The second project pom.xml look like this:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.test</groupId>
<artifactId>test2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<profiles>
<profile>
<id>TEST</id>
<dependencies>
<dependency>
<groupId>org.test</groupId>
<artifactId>test1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
Then I set profile TEST as an active on Maven panel in the project properties dialog and made sure dependency resolution from Workspace is enabled there.
After that you can run any classes from test2 project's src/main/java and generated classpath looks like this:
C:\Dev\Java1.6\bin\javaw.exe -Dfile.encoding=Cp1252
-classpath C:\Dev\Workspace\test2\target\classes;C:\Dev\Workspace\test1\target\classes org.test2.Test2
Note, that dependencies with runtime scope only works for "Java Application" launch configuration type in Eclipse, but not for "JUnit" launch configuration, which uses different classpath resolver provided by m2eclipse's JDT integration.
It seems dependencies that are within profiles of dependent projects (transitive) dont give there runtime dependencies to the person who depends on them, This seems strange.
A work around was to add the profiles (containing the dependencies) to a parent then the children inherit the dependencies.
i.e. introduce a parent to A, I could have put them directly in A as YMomb kindly suggested. but its the inheritance aspect of this issue I needed to resolve as I have lots of projects As.

Maven assembly plugin: run only one descriptor

I have a project which has several custom descriptors written for the assembly plugin. Is there a way to run only one of those descriptors at a time instead of the whole bunch? I tried using the descriptors switch as documented here, passing in the full path to the one descriptor that I wanted to run, but instead it's running all of the descriptors in my app's main pom file, seeming to ignore the switch I specified.
Probably the easiest way to do so, is by using Maven Profiles.
Define some profiles in your pom.xml:
<profiles>
<profile>
<id>profile-1</id>
<properties>
<assembly-config>assem1.xml</assembly-config>
</properties>
</profile>
<profile>
<id>profile-2</id>
<properties>
<assembly-config>assem2.xml</assembly-config>
</properties>
</profile>
</profiles>
Then you use that particular property for the configuration of the assembly plugin:
...
<descriptor>src/main/assembly/${assembly-config}</descriptor>
...
Then run your maven build with the -P option: mvn -P profile-1 compile
So, summarized, if you choose a profile at buildtime, the property assembly-config will be set depending on the defined profile. The assembly configuration depends in that case on the chosen profile.
Hope this helps!