Projet

Général

Profil

Actions

MAY Maven Eclipse Setup » Historique » Révision 13

« Précédent | Révision 13/15 (diff) | Suivant »
Anonyme, 24/10/2014 09:36


MAY Maven Eclipse Setup

Install the Maven Eclipse Plugin

The Maven Eclipse Plugin, also named M2E, is available as part of the normal Eclipse distribution but must be explicitly installed.

Go to Help / Install New Software... and select the All available site in the drop-down list (it may take some time to load).

Expand the Collaboration category and select m2e - Maven Integration for Eclipse.

Click Next, finish the installation procedure and restart Eclipse when asked to.

Convert an Existing Project to Maven

The first step is to convert your project into a Maven project.
To do this, right click on your project and on Configure / Convert to Maven Project.

You will be asked to create a new POM file. Just click Finish after editing the package, name and version if desired.

Alternatively, you can directly create a Maven project, this is out of scope of this document.

Maven and MAY

In Maven, the POM file (pom.xml, at the root of the project) contains information about the project and its dependencies.
By default, the POM file looks something like this:

<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>XXX</groupId>
    <artifactId>XXX</artifactId>
    <version>XXX</version>

    <build>
        <sourceDirectory>src</sourceDirectory>
        <resources>
            <resource>
                <directory>src</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

In particular, it contains configurations to set the source directory or the compiler version.

Because MAY is a plugin that generates Java code from the SpeADL code in a separate folder, we need to tell Maven about this supplementary source folder with the following configuration:

<project ...>
    ...
    <build>
        ...
        <plugins>
            ...
            <!-- This configure maven to take into account the SpeADL code in the speadl-gen directory -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.8</version>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>speadl-gen</source>
                            </sources>
                        </configuration>
                    </execution>
                    <!-- The following is only needed so that speadl files are included 
                        in the generated maven artifact -->
                    <execution>
                        <id>add-resource</id>
                        <goals>
                            <goal>add-resource</goal>
                        </goals>
                        <configuration>
                            <resources>
                                <resource>
                                    <directory>${project.build.sourceDirectory}</directory>
                                    <includes>
                                        <include>**/*.speadl</include>
                                    </includes>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            ...
        </plugins>
        ...
    </build>
</project>

Apply this new configuration: right-click on the project Maven / *Update Project..., then select the project and click Ok.

Maven and the MAY Component Library

With MAY, we provide a component library that we distribute through the Maven dependencies mechanism.
Any dependency specified in the POM file is automatically added to the classpath of the project and can be directly used.

In order to specify a dependency, it is needed to specify which version of the dependency is needed.
With the component library, the versioning follows the versioning of MAY for the first two digits and is specific to the library for the last one.

So for example, for MAY 3.4.X, one should use the component library 3.4.X.

Starting from version 3.4.X, the component library is available from Maven Central.

Before that, it is needed to add the following repository to the requiring POM file:

    <repositories>
        <repository>
            <id>fr.irit.smac</id>
            <url>http://www.irit.fr/~Victor.Noel/maven-repos/</url>
        </repository>
    </repositories>

The following configuration adds the dependency to the POM file:

<project ...>
    ...
    <!-- We store the version of the component library in a property used later -->
    <properties>
        <may-lib-version>3.4.0</may-lib-version>
    </properties>

    <!-- We declare the dependency to the component library.
             Its dependencies will be also be available. -->
    <dependencies>
        <dependency>
            <groupId>fr.irit.smac.lib.may</groupId>
            <artifactId>common-components</artifactId>
            <version>${may-lib-version}</version>
        </dependency>
    </dependencies>

    <!-- OPTIONAL: we declare the repository where the component library can be found -->
    <repositories>
        <repository>
            <id>fr.irit.smac</id>
            <url>http://www.irit.fr/~Victor.Noel/maven-repos/</url>
        </repository>
    </repositories>
    ...
    <build>
    ...
    </build>
</project>

Possible issues and resolutions

Errors on the Project

You may get an error message saying your project configuration is out of date with your new pom.xml.

Update it: right click on your project Maven / Update Project... and click Ok.

Errors in the POM File

You also may get an error saying the following in the POM file:

Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:build-helper-maven-plugin:1.8:add-source (execution: add-source, phase: generate-sources)

Click on Discover new m2e connectors, it should pre-check buildhelper, simply click Finish to accept and do the installation.

Mis à jour par Anonyme il y a plus de 11 ans · 15 révisions