Matrix Bai
Matrix Bai

Reputation: 1107

M2E didn't work with exist Maven project

I have an android project, I use maven to manage it and it works well in command line. The construction as below:

My Project

|--android
|----src
|----pom.xml
|----......
|--common
|----src
|----assets
|----repo
|--desktop
|--pom.xml

I put shared code and assets in common directory. and the pom.xml in android directory is:

<project>
........
<dependencies>
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android</artifactId>
        <version>2.2.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
    <groupId>com.badlogic.gdx</groupId>
    <artifactId>gdx</artifactId>
    <version>0.9.1</version>
    </dependency>
    <dependency>
    <groupId>com.badlogic.gdx</groupId>
    <artifactId>gdx-backend-android</artifactId>
    <version>0.9.1</version>
    </dependency>
    <dependency>
    <groupId>com.google.ads</groupId>
    <artifactId>GoogleAdMobAdsSdk</artifactId>
    <version>4.0.4</version>
    </dependency>
</dependencies>
<build>
    <finalName>${project.artifactId}</finalName>
    <sourceDirectory>src</sourceDirectory>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <version>3.0.0-alpha-14</version>
                <extensions>true</extensions>
            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>
        <plugin>
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <configuration>
                <sdk>
                    <!-- platform or api level (api level 4 = platform 1.6)-->
                    <platform>8</platform>
                </sdk>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals><goal>add-source</goal></goals>
                    <configuration>
                        <sources>
                            <source>../common/src</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <resources>
    <resource>
        <directory>../common/assets</directory>
    </resource>
    </resources>
</build>
<repositories>
  <repository>
<id>libs</id>
<url>file://${basedir}/../common/repo/</url>
  </repository>
</repositories>
</project>

As you can see above, I set addition src dir with build-helper-maven-plugin, and set the resource dir to common/src, I also have a local repository in common/repo to manage my 3rd lib.

Everything is fine when I use command line, I can 'mvn install android:deploy' with my phone. However when I import it into Eclipse with M2E, I confront below problems

The addition src directory I added in pom.xml didn't show in the Eclipse workspace, so the code in android/src can't find the package.

If I link source folder manually in Eclipse, it tell me should update the maven configuration, and I did, another error"Cannot nest 'android/gen' inside 'android'. To enable nesting exclude 'gen' from 'android'" show up.

I totally confused by this mess. Anyone confront the same problem and why I can use maven in command line and can't in M2E, thank you?

Upvotes: 4

Views: 1433

Answers (1)

Matrix Bai
Matrix Bai

Reputation: 1107

I figured it out, a mistake in my pom.xml.

After add maven-compiler-plugin info to pom.xml, everything is OK.

Upvotes: -2

Related Questions