Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[m2e-users] Maven build with resolve worspace artifacts possible bug

Hello,

I've found possible bug in the way how m2e resolves workspace artifacts when running as maven build from run as dialog in Eclipse. And therefore I'd like to discuss here if it is really a bug.

The problem is that if a project A produces secondary artifact that is a different type (packaging) than the main artifact... then project B with dependency on the secondary artifact from project A doesn't get the dependency resolved into the workspace project but into the local repository.
This happens when running maven script from Run as Maven build dialog with workspace artifact resolution enabled.
On the other hand it is ok when the build is executed by the Eclipse maven builder as a part of Eclipse build.


To be more verbose:
1. project A produces 2 artifacts of different types (e.g. war as main and jar as secondary)
2. project B has a dependency on secondary artifact from project A (e.g. on jar artifact from project A)
3. both projects are imported in Eclipse workspace
4. open Maven build dialog from Run as dialog of project B
5. enable the dependency workspace resolution
6. run any phase (initialize is enough)
7. when running maven build of project B the secondary artifact of project A is not resolved to workspace but into to local repository

However if the initialize phase of project B is executed by maven builder itself (i.e. during the compilation of the workspace) the secondary artifact is resolved correctly.



How to reproduce the problem (each number refers to one step from above):
1.
a) create simple war project A as archetype 'org.apache.maven.archetypes:maven-archetype-webapp'
b) add creation of secondary artifact that is different type than the main one. The easiest way is to enable attach artifact option in war plugin which produces jar artifact.
<build>
        <finalName>webA</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <attachClasses>true</attachClasses>
                </configuration>
            </plugin>

        </plugins>
    </build>

2.
a) create simple war project B as archetype 'org.apache.maven.archetypes:maven-archetype-webapp'
d) add dependency which refers to the 'attach classes' artifact of project A (the important part is that the type is jar and not war)
<dependency>
            <groupId>org.test</groupId>
            <artifactId>webA</artifactId>
            <type>jar</type>
            <classifier>classes</classifier>
            <version>1.0-SNAPSHOT</version>
        </dependency>

3.4.5.6. are hopefully clear enough

7.
a) To get information how dependencies are resolved I used maven dependency plugin (to store dependencies paths in properties) and gmaven plugin (to print those paths on the screen)
b) to configure the dependency plugin:
<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>properties</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
c) to configure the gmaven plugin:
<plugin>
                <groupId>org.codehaus.gmaven</groupId>
                <artifactId>gmaven-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <id>print</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                        <configuration>
                            <source>
                                project.dependencies.each() {
                                identifier = "${it.groupId}:${it.artifactId}:${it.type}"
                                identifier += it.classifier == null ? "" : ":${it.classifier}"
                                println "${it} resolves to: " + project.properties[identifier]
                                }
                            </source>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

When such configuration is run as Maven build we can see that the dependency points to the local repo instead to the 'target/classes' directory of project A
If I run eclipse with allocated console (e.g. as java) (It is not visible in Maven console in Eclipse (the same issue as with antrun)) I can see in stdout of Eclipse that gmaven outputs correctly resolved dependencies to the workspace during the normal build of the project B.

I'm sorry that the formatting of the xml fragments I included is probably not nicely indented.

Thanks for your support!

Stepan Vavra

Back to the top