Question

I am working on a new project which is a plugin for a product.

I use maven to build my plugin (zip) but I need to reference the source code of the product which is defined in my Eclipse workspace. But this source code is not managed by Maven and I do not want to migrate it.

Is it possible to refers this workspace project by any way? (maven plugins, workaround welcome).

The dependency is just needed for the compilation inside Eclipse but will not be packaged in the plugin itself (provided scope).

I have also m2e in Eclipse and I want to keep this configuration when I make a "Maven Update".

UPDATE: I am looking for a solution which will work with a mvn clean install on a command line because I want to be able to execute the build from a CI platform (e.g. Jenkins)

Était-ce utile?

La solution 3

Because I have already the compiled source and I do not need to recompile them (or to modify anything) I decided to package them using the pom assembly.

I made a separate project (under the same parent's than my plugins developement projects) called like openemm-src:

  Parent project (openemm-plugin-dev)
       |- plugin-1
       |- plugin-2
       |- openemm-src 
              |- pom.xml 

The pom.xml for the openemm-src project looks like:

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>openemm.plugin.dev</groupId>
        <artifactId>plugin</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>
    <artifactId>openemm-src</artifactId>
    <version>1.0.0</version>
    <packaging>pom</packaging>
    <name>OpenEMM Source Code Library</name>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptors>
                        <descriptor>src/assembly/src-plugin.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id> <!-- this is used for inheritance merges -->
                        <phase>package</phase> <!-- bind to the packaging phase -->
                        <goals>
                            <goal>single</goal>
                        </goals>
                    <xecution>
                </executions>
            </plugin>

        </plugins>
    </build>
</project>

and the file src/assembly/src-plugin.xml:

<assembly>
    <formats>
        <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>

    <fileSets>
        <fileSet>
            <directory>build/classes</directory>
            <outputDirectory></outputDirectory>
        </fileSet>
    </fileSets>
</assembly> 

After this, I refers the jar from the siblings projects like this:

<dependency>
    <groupId>openemm.plugin.dev</groupId>
    <artifactId>openemm-src</artifactId>
    <version>1.0.0</version>
    <scope>provided</scope>
</dependency>

This solution is looking more like a workaround, but this is because the OpenEMM project does not have any "Plugin Template Project" to be managed with Maven.

Note this is just a partial configuration and I had also to refers to the Agnitas libraries which did not contains all the source code (both were necessary to compile my code).

Autres conseils

Simply use Project -> Properties -> Java Build Path -> Projects -> Add

If you need to compile it outside Eclipse you can add a dependency to physical jar location:

 <dependency>
    <groupId>test</groupId>
    <artifactId>test</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/test.jar</systemPath>
</dependency>

You might consider using the antrun plugin to trigger the compilation of your source code in the external project linked to your compile phase. You could even copy your .class files into your target folder so the runtime classpath finds them

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top