URLs
-
Project home (this page)
Do you want to improve this page? Please edit it on GitHub. |
Description
This repository demonstrates how you can use the goal eclipse-settings
of the eclipse-settings-maven-plugin (GitHub) to synchronize the eclipse-settings files between multiple projects.
The *.prefs
files stored inside a maven artifact are extracted into each .setting
folder of each project using the maven plugin.
This repository provides some example projects that use the maven plugin. They are located in the example-use folder.
Maven structure
From a maven point of view you have:
-
a parent pom file and several child artifacts:
-
wrong1 pom file (contains a compile error on purpose)
-
skipped1 pom file (is not an eclipse project on purpose)
-
another aggregator artifact other pom file that doesn’t have
parent
as parent pom.
To make the maven structure a little more complex, the parent pom only aggregates project1
and project2
and not wrong1
.
The other
pom aggregates parent
, wrong1
and skipped1
.
project1
is a dependency of project2
.
Compile at the root
You can compile parent
, project1
and project2
by running maven at inside of the example-use folder
cd example-use mvn compile
You should get a log like this:
[INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary: [INFO] [INFO] parent ............................................. SUCCESS [ 0.011 s] [INFO] project1 ........................................... SUCCESS [ 2.369 s] [INFO] project2 ........................................... SUCCESS [ 0.024 s] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------
Compile all projects
Because of the complex aggreation structure, to compile all the projects you need to run maven in the other folder. Only this pom file aggregates all the maven artifacts contained in the example.
cd example-use/other mvn compile
For demonstration purpose there is a compile error in the wrong1
project.
The build result should be:
[INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] ***/wrong1/src/main/java/example/Temporary.java:[5,17] not a statement [ERROR] ***/wrong1/src/main/java/example/Temporary.java:[5,25] ';' expected [INFO] 2 errors [INFO] ------------------------------------------------------------- [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary: [INFO] [INFO] parent ............................................. SUCCESS [ 0.007 s] [INFO] project1 ........................................... SUCCESS [ 2.219 s] [INFO] project2 ........................................... SUCCESS [ 0.033 s] [INFO] wrong1 ............................................. FAILURE [ 0.775 s] [INFO] skipped1 ........................................... SKIPPED [INFO] other .............................................. SKIPPED [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------
Projects in Eclipse IDE
The artifacts can of course be imported into Eclipse IDE.
Each of them is a valid Eclipse project.
The requested metadata files (.project
and .classpath
) are contained in the git repository:
If you want to import the projects into Eclipse, just open the Import dialog with example-use folder as root directory and in the Options section, make sure that Search for nested projects is checked. You should see the list of projects and you can materialize them in the workspace with the Finish button.
and select Existing Projects into Workspace in the import source list. Indicate theMaven plugin usage
Setup
The parent project is configured to generate four *.prefs
files inside each .settings
folder.
-
org.eclipse.core.resources.prefs
-
org.eclipse.jdt.core.prefs
-
org.eclipse.jdt.ui.prefs
-
org.eclipse.m2e.core.prefs
This section provides a step-by-step overview of the configuration.
You can also refer directly to the pluginManagement
section of the parent pom.
The configuration is similar to any maven plugin:
<plugin>
<groupId>org.eclipse.scout</groupId>
<artifactId>eclipse-settings-maven-plugin</artifactId>
<version>3.0.3</version>
<dependencies>
<!-- ... add dependencies here: source for the .settings files ... -->
</dependencies>
<!-- ... add configuration here ... -->
</plugin>
In this example the different *.prefs
files should be copied from org.eclipse.scout.rt-settings artifact of the Eclipse Scout project.
This artifact is defined as a dependency of the eclipse-settings-maven-plugin
itself (and not of the parent project).
<dependency>
<groupId>org.eclipse.scout.rt</groupId>
<artifactId>org.eclipse.scout.rt-settings</artifactId>
<version>6.0.200.0</version>
</dependency>
In the configuration section, the location of each *.prefs
that will be copied to each project is defined.
In this case, the 4 files should be moved to the .settings
folder.
<configuration>
<additionalConfig>
<file>
<name>.settings/org.eclipse.core.resources.prefs</name>
<location>/org.eclipse.core.resources.prefs</location>
</file>
<file>
<name>.settings/org.eclipse.jdt.core.prefs</name>
<location>/org.eclipse.jdt.core.prefs</location>
</file>
<file>
<name>.settings/org.eclipse.jdt.ui.prefs</name>
<location>/org.eclipse.jdt.ui.prefs</location>
</file>
<file>
<name>.settings/org.eclipse.m2e.core.prefs</name>
<location>/org.eclipse.m2e.core.prefs</location>
</file>
</additionalConfig>
</configuration>
Because the eclipse-settings-maven-plugin
is configured in the pluginManagement
section, the configuration will be applied for all children of the parent pom.
There is one exception in the skipped1
project: this child pom is additionally configured to skip the configuration made in the parent pom.
<plugin>
<groupId>org.eclipse.scout</groupId>
<artifactId>eclipse-settings-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
Sync the prefs files
To synchronize the configured *.prefs
files on a project (existing files will be replaced with the configured one), a single maven call is enough:
mvn org.eclipse.scout:eclipse-settings-maven-plugin:eclipse-settings
It is possible to call it on a single artifact.
More interesting is to call it on an aggregator pom, the parent
project or the other
project in our example.
In this case, the settings files will be synchronized for each module in the maven reactor.
If you call the goal in the parent project like this:
cd example-use mvn org.eclipse.scout:eclipse-settings-maven-plugin:eclipse-settings
The settings files will be synchronized in the parent
, project1
and project2
projects.
The maven log looks like this:
[INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Reactor Build Order: [INFO] [INFO] parent [INFO] project1 [INFO] project2 [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building parent 1.0 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- eclipse-settings-maven-plugin:3.0.3:eclipse-settings (default-cli) @ parent --- [INFO] Project configured. [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building project1 1.0 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- eclipse-settings-maven-plugin:3.0.3:eclipse-settings (default-cli) @ project1 --- [INFO] Project configured. [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building project2 1.0 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- eclipse-settings-maven-plugin:3.0.3:eclipse-settings (default-cli) @ project2 --- [INFO] Project configured. [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary: [INFO] [INFO] parent ............................................. SUCCESS [ 1.462 s] [INFO] project1 ........................................... SUCCESS [ 0.059 s] [INFO] project2 ........................................... SUCCESS [ 0.058 s] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------
If the same goal is called in the other project like this:
cd example-use/other mvn org.eclipse.scout:eclipse-settings-maven-plugin:eclipse-settings
The settings files will be synchronized the parent
, project1
, project2
and wrong1
projects.
This will be the case even if the wrong1
project cannot be compiled due to a compile error.
In the project skipped1
, no settings files will be copied, because the project is configured to ignore the configuration made in the parent pom.
The maven log for the skipped1
artifact looks like this:
[INFO] ------------------------------------------------------------------------ [INFO] Building skipped1 1.0 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- eclipse-settings-maven-plugin:3.0.3:eclipse-settings (default-cli) @ skipped1 --- [INFO] Skipping project settings configuration. [INFO]
In the other
project, no settings file will be generated, because nothing is configured (other
do not have parent
as parent pom).
The maven log for the other
artifact looks like this:
[INFO] ------------------------------------------------------------------------ [INFO] Building other 1.9 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- eclipse-settings-maven-plugin:3.0.3:eclipse-settings (default-cli) @ other --- [WARNING] No settings specified. [ERROR] Project not configured.
Sync the prefs files in Eclipse
Of course you can execute the same maven command inside Eclipse using the user interface.
Select the corresponding pom.xml
in the Package Explorer (take as example the one in the parent
Project) and choose in the context menu.
In the Edit Configuration dialog indicate org.eclipse.scout:eclipse-settings-maven-plugin:eclipse-settings
in the Goals field.
To perform this task quicker, you can run one of the *.launch
file that are present in the repository.
Select the sync eclipse-settings parent.launch file in the Package Explorer and select .
Get in touch
Use the Sync eclipse-settings example issue tracker on GitHub.
You can also contact me on Twitter: @j2r2b