Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[m2e-users] M2E Update Project issue

I am putting together a large Eclipse RCP project using Eclipse 3.7.2, Tycho 0.15.0 and m2e 1.1 latest. On several occasions, I have seen errors along the lines of "The project is not up to date with the pom. Run Update Project" (paraphrasing from memory). This happens more often when updating a project from source control such as when committing changes from one PC and updating on another. The problem is that running Maven->Update Project... does not always resolve the problem immediately - it sometimes has to be run twice - with no net change in any of the project data.

I've managed to extract and simplify a single small project that can be used to repeat some of the anomalies I am seeing. This project simply repackages a standard jar library (Log4j) as an OSGi plug-in. There may be better ways to do this, and as an aside I'd be interested to hear them, but this is really irrelevant for now as I get similar issues with a larger multi-package maven-structured Java project too.

The attached .zip contains the necessary Eclipse project files.
  1. Create a new general project (File->New->Project... then General->Project)
  2. Copy the contents of the .zip to the project (overwriting the existing .project file).
  3. Right-click project, choose Run As->Maven build
  4. In the 'Edit Configuration' dialogue, type 'package' into the Goals field
  5. Click 'Refresh' tab; click 'Refresh resources upon completion'
  6. Click 'Run'

Maven should now download some artifacts and build the OSGi version of the Log4j library.

Next, open the .classpath from the project so you can see what happens during the next steps. (If you can't see .classpath, open the Package Explorer menu - the down-pointing white triangle - and select 'Filters...'. In the next dialogue, uncheck '.* resources' and click OK.)

Now here is the weird behaviour...
   a. Right-click the project and select 'Maven->Update Project...'. Click OK in the next dialogue.
   b. Notice what happens to the contents of .classpath

Repeat steps a and b a few more times and notice how eventually the project toggles between two states, one of which is OK (but contains more than necessary) and the other which has errors - the .classpath only references a 'classes' folder (that is also not necessary), but loses the reference to the needed library.

I'm not sure if this is purely an m2e bug or an understanding/configuration issue that has caused m2e to behave strangely. Any help gratefully received. (NB: although I'm using m2e 1.1 latest from sonatype's repo, I'm seeing similar issues with m2e 1.0 from eclipse.org).

Dave.

P.S. In case anyone can't access the .zip file, I've listed the 5 files that seed the Eclipse project below

=====================================================
META-INF\MANIFEST.MF
=====================================================
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Log4j as OSGI plugin
Bundle-SymbolicName: jar2plugin.log4j
Bundle-Version: 1.2.16
Bundle-ClassPath: target/libs/log4j-1.2.16.jar
Export-Package: org.apache.log4j,
 org.apache.log4j.xml
Bundle-RequiredExecutionEnvironment: JavaSE-1.6


=====================================================
.classpath
=====================================================
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="lib" path="target/libs/log4j-1.2.16.jar"/>
</classpath>


=====================================================
.project
=====================================================
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
	<name>jar2plugin.log4j</name>
	<comment></comment>
	<projects>
	</projects>
	<buildSpec>
		<buildCommand>
			<name>org.eclipse.pde.ManifestBuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
		<buildCommand>
			<name>org.eclipse.m2e.core.maven2Builder</name>
			<arguments>
			</arguments>
		</buildCommand>
	</buildSpec>
	<natures>
		<nature>org.eclipse.m2e.core.maven2Nature</nature>
		<nature>org.eclipse.pde.PluginNature</nature>
		<nature>org.eclipse.jdt.core.javanature</nature>
	</natures>
</projectDescription>


=====================================================
build.properties
=====================================================
bin.includes = META-INF/,\
               .,\
               target/libs/log4j-1.2.16.jar


=====================================================
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>jar2plugin</groupId>
  <artifactId>jar2plugin.log4j</artifactId>
  <version>1.2.16</version>
  <packaging>eclipse-plugin</packaging>

  	<properties>
		<tycho-version>0.15.0</tycho-version>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.16</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
	</dependencies>

  	<build>
		<plugins>

			<plugin>
				<groupId>org.eclipse.tycho</groupId>
				<artifactId>tycho-maven-plugin</artifactId>
				<version>${tycho-version}</version>
				<extensions>true</extensions>
			</plugin>

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
				<executions>
					<execution>
						<id>copy-dependencies</id>
						<phase>initialize</phase>
						<goals>
							<goal>copy-dependencies</goal>
						</goals>
						<configuration>
							<excludeTransitive>true</excludeTransitive>
							<includeArtifactIds>log4j</includeArtifactIds>
							<outputDirectory>target/libs</outputDirectory>
							<overWriteReleases>true</overWriteReleases>
							<overWriteSnapshots>true</overWriteSnapshots>
							<overWriteIfNewer>true</overWriteIfNewer>
						</configuration>
					</execution>
				</executions>
			</plugin>

		</plugins>

		<pluginManagement>
			<plugins>
				<plugin>
					<groupId>org.eclipse.m2e</groupId>
					<artifactId>lifecycle-mapping</artifactId>
					<version>1.0.0</version>
					<configuration>
						<lifecycleMappingMetadata>
							<pluginExecutions>
								<pluginExecution>
									<pluginExecutionFilter>
										<groupId>org.apache.maven.plugins</groupId>
										<artifactId>maven-dependency-plugin</artifactId>
										<versionRange>[0.0.0,)</versionRange>
										<goals>
											<goal>copy-dependencies</goal>
											<goal>unpack</goal>
										</goals>
									</pluginExecutionFilter>
									<action>
										<execute>
											<runOnIncremental>false</runOnIncremental>
										</execute>
									</action>
								</pluginExecution>
							</pluginExecutions>
						</lifecycleMappingMetadata>
					</configuration>
				</plugin>
			</plugins>
		</pluginManagement>
	</build>

</project>

Attachment: m2e-up-issue.zip
Description: m2e-up-issue.zip


Back to the top