Since both use the target directory, Eclipse's build output sometimes interferes with the output of mvn builds run at the command line.
What's the best way to separate the two outputs?
Insert the following into your pom.xml. Eclipse's "m2e.version" property will activate the following profile which alters the location of the Eclipse build
<profiles>
<profile>
<id>IDE</id>
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<build>
<!-- Put the IDE's build output in a folder other than target, so that IDE builds don't interact with Maven builds -->
<directory>target-ide</directory>
</build>
</profile>
</profiles>
Official way is presented here:
http://wiki.eclipse.org/M2E_FAQ#How_to_configure_Maven_project_to_use_separate_output_folders_in_Eclipse
I personally don't do something like this. Usually I basically disable auto-build in Eclipse since most builds I do from the console anyway. But if you really want it, here you are.
If you use maven-eclipse-plugin instead of M2Eclipse, here's the definition you want in order to change the Eclipse output directory:
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<buildOutputDirectory>target-eclipse/classes</buildOutputDirectory>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
Related
I have an application with two versions: swt and rap. Therefore in my plugins I have optional dependencies on both of them and when there is missing one, the other is present and vice versa. Problem is, that in Tycho I can only require or ignore optional dependencies. Is there a way to treat this somehow?
My suggestion: not use optional dependencies. In my single sourced RCP/RAP project, i'm create several empty/"fake" plugins, only id matters with no source.
RAP build
org.eclipse.jface.databinding
org.eclipse.ui
org.eclipse.ui.forms
RCP build
org.eclipse.rap.jface.databinding
org.eclipse.rap.ui
org.eclipse.rap.ui.form
well I have found a solution to this. it is having two separate profiles for rcp and rap, ignore optional dependencies and define extra requirement for each bundle I need in that particular profile eg:
<profiles>
<profile>
<id>rap</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>maven.profile</name>
<value>rap</value>
</property>
</activation>
<repositories>
...
</repositories>
<modules>
...
</modules>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<dependency-resolution>
<optionalDependencies>ignore</optionalDependencies>
<extraRequirements>
<requirement>
<type>eclipse-plugin</type>
<id>org.eclipse.rap.ui</id>
<versionRange>0.0.0</versionRange>
</requirement>
<requirement>
<type>eclipse-plugin</type>
<id>org.eclipse.rap.ui.views</id>
<versionRange>0.0.0</versionRange>
</requirement>
</extraRequirements>
</dependency-resolution>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
this is what i have in top level pom.xml, if some bundle that is part of your build have optional dependecy on other bundle from that build there will be circular dependency if you add the extra requirement in the top level pom. solution is simply to add the extra requirement to pom of the bundle that has the dependency - you just have to put it inside a profile it is meant to be in
Is there a way to automatically activate a maven profile when the project is opened in IntelliJ IDEA?
For eclipse, this can be done by using the property m2e.version for activation and I thought there may be something similar for IDEA.
<profiles>
<profile>
<id>m2e</id>
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<build>
<directory>${project.basedir}/eclipse-target</directory>
</build>
</profile>
</profiles>
What I basically want, is to have a separate build directory for IDEA. This is useful to run mvn commands on the command line without messing with the IDE.
IntellJ sets the idea.version property when running maven run configurations. It also sets this property while detecting default profiles when importing a maven based project.
<profile>
<id>activeInIdea</id>
<activation>
<property>
<name>idea.version</name>
</property>
</activation>
<build>
<directory>${project.basedir}/eclipse-target</directory>
</build>
</profile>
After opening the project in IntelliJ the profile (in the example above called activeInIdea) is already pre-selected.
When imported as Maven project, IntelliJ will detect your maven profiles and import them as well. It will allow you to activate profiles on import and will even enable profiles which appear enabled during import. You can toggle the profiles after import in the Maven Projects tool window.
If your question aims on how to save you one click to activate the profile, then I haven't answered your question. But if you just missed the Maven Projects window, then here you go.
When invoking importing maven projects into eclipse from git using "Import Maven Projects" the m2e plugins to seems to generate a new .project and .classpath and some other files even though those files are checked in.
To get around this problem I would like to not check in any eclipse specific files, but there are customizations made to each project file such as custom save actions, or changes to the validation to ignore specific things, or changes to the javascript configuration for a dynamic web project that need to be preserved, so either those files need to checked or those settings need to be generated by m2e.
Any way to use m2e to configure the eclipse project validators?
We had a similar problem in the past. We solved it by
don't checkin eclipse specific files (svn ignore, git ignore, ...)
Use Workspace Mechanic plugin to keep eclipse settings the same accross development machines / developers.
The other answer has suggested the solution with eclipse. But if you are flexible with using a different IDE, I suggest using Netbeans with git. I tested both IDEs and finally found out I could save time in different cases using Netbeans! No such problems as mentioned above.
I made m2e-codestyle-maven-plugin for another purpose but it should serve what you need as well (in my case I wanted to set the default settings to have all validations turned on from my coding-standards project.
The key thing you have to do is fork a copy of my coding-standards project and add/change the appropriate setting in org.eclipse.wst.validation.prefs namely
vals/org.eclipse.wst.xml.core.xml/global=FF03
To disable the validations for XML for example. You can have it activated only on m2e by using profiles as shown here
https://github.com/trajano/jee/blob/master/jee-domain-api/pom.xml#L24
<profile>
<id>m2e</id>
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>net.trajano.mojo</groupId>
<artifactId>m2e-codestyle-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>configure</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>net.trajano</groupId>
<artifactId>coding-standards</artifactId>
<version>${coding-standards.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
I have custom checkstyle checks file (called checks.xml), and I'm trying to use that same file in both maven and eclipse. It all works well, except for the SuppressionFilter.
In this checks.xml file, I have
<module name="SuppressionFilter">
<property name="file" value="src/main/resources/checkstyle/checkstyle-suppressions.xml"/>
</module>
This works when I run through maven. However, when I run through eclipse, I need to change the config to be
<module name="SuppressionFilter">
<property name="file" value="${basedir}/src/main/resources/checkstyle/checkstyle-suppressions.xml"/>
</module>
If I run with the ${basedir} property with maven though, I get the error that property ${basedir} has not been set.
Is there a way use this same configuration file in both maven and eclipse? I feel like there should be, but I'm just missing something on how to properly populate the suppression filter.
thanks,
Jeff
This is hell. Eclipse and Maven handle suppressions different and don't share variables.
Derived from Rolf Engelhard
So in pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.8</version>
<configuration>
<propertyExpansion>config_loc=${basedir}/src/main/checkstyle</propertyExpansion>
<configLocation>${basedir}/src/main/checkstyle/checkstyle.xml</configLocation>
<suppressionsLocation>${basedir}/src/main/checkstyle/suppressions.xml</suppressionsLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
Now in checkstyle.xml (${config_log} is an Eclipse specific thing, but by specifying it in the pom we make it available to maven as well):
<module name="SuppressionFilter">
<property name="file" value="${config_loc}/suppressions.xml" />
</module>
And if you're using maven-site-plugin or any other plugins that also rely on CheckStyle don't forget to update those to have the config_loc property as well (or declare it global to the pom, though I wasn't able to get this to work properly).
Sure there is a way to use the same configuration file in both maven and eclipse but it requires a little setup first. I wrote a blog post on how to achieve this even for a multi-module maven project. see: maven-checkstyle-and-eclipse
<propertyExpansion>basedir=${session.executionRootDirectory}</propertyExpansion> works for me, but only when added to the <plugin>node, not to <execution>!
project.basedir does not work well in multi-module projects, because it will point to the submodule folder instead of the root folder.
You could try defining ${basedir} as a property in your pom.
See the pom reference quick overview.
<property>
<name>basedir</name>
<value>${project.basedir}</value>
</property>
I have a Maven project that derives the path to a native library using properties which can be set in local profiles. For example:
<project>
...
<build>
...
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<environmentVariables>
<LD_LIBRARY_PATH>${foo.libdir}</LD_LIBRARY_PATH>
</environmentVariables>
<fork>always</fork>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>foo-default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<foo.libdir>/usr/local/lib</foo.libdir>
</properties>
</profile>
</profiles>
</project>
When I'm working with this project in Eclipse using the M2Eclipse plugin, I'd like to be able to set up run configurations that also reference this path in the same was (e.g., so I can run the Eclipse debugger on the project). Is there a way to access the Maven property from Eclipse, e.g., so that could set LD_LIBRARY_PATH in the run configuration using a variable like ${maven_property:foo.libdir}?
I do not think so.
Your maven script could refer to environment variable that you could define in the environment tab of your launch configuration
But the other way around (i.e. your configuration resolving at launch time some maven script property) is not, as far as I know, possible.