为什么maven会创建奇怪的android-project-structure

时间:2016-05-30 09:26:34

标签: java android maven

使用How to build a Maven Android project in eclipse创建maven项目会创建两个90%相同的模块。

这是父母pom的一部分:

<profiles>
    <profile>
        <!-- the standard profile runs the instrumentation tests -->
        <id>standard</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <modules>
            <module>zopp.server</module>
            <module>zopp.server-it</module>
        </modules>
    </profile>
    <profile>
        <!-- the release profile does sign, proguard, zipalign ... but does not 
            run instrumentation tests -->
        <id>release</id>
        <!-- via this activation the profile is automatically used when the release 
            is done with the maven release plugin -->
        <activation>
            <property>
                <name>performRelease</name>
                <value>true</value>
            </property>
        </activation>
        <modules>
            <module>zopp.server</module>
        </modules>
    </profile>
</profiles>

<modules>
    <module>zopp.server</module>
    <module>zopp.server-it</module>
</modules>

为什么必须将其执行到其他模块?

Zopp项目有2个android-apps和1个api-library。这是建筑结果:

[INFO] android.zopp ....................................... SUCCESS [  0.107 s]
[INFO] zopp.server - Parent ............................... SUCCESS [  0.006 s]
[INFO] zopp.server - Application .......................... SUCCESS [  2.122 s]
[INFO] zopp.server-it - Integration tests ................. SUCCESS [ 15.914 s]
[INFO] zopp.client - Parent ............................... SUCCESS [  0.006 s]
[INFO] zopp.client - Application .......................... SUCCESS [  0.580 s]
[INFO] zopp.client-it - Integration tests ................. SUCCESS [ 15.916 s]
[INFO] zopp.api ........................................... SUCCESS [  0.506 s]

如何将其击败为每个应用只有一个项目?

编辑:在根和所有服务器部件之间添加完整的poms。

server-pom

<?xml version="1.0" encoding="UTF-8"?>
<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>de.e-nexus</groupId>
        <artifactId>zopp.server-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>zopp.server</artifactId>
    <packaging>apk</packaging>
    <name>zopp.server - Application</name>

    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>${parent.groupId}</groupId>
            <artifactId>zopp.api</artifactId>
            <version>${parent.version}</version>
        </dependency>
    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <!-- use the copy resources instead of resources, which adds it to 
                            the eclipse buildpath -->
                        <phase>initialize</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.basedir}/res</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${project.basedir}/src/templates/res</directory>
                                    <targetPath>${project.basedir}/res</targetPath>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <manifest>
                        <debuggable>true</debuggable>
                    </manifest>
                </configuration>
                <executions>
                    <execution>
                        <id>manifestUpdate</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>manifest-update</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>alignApk</id>
                        <phase>package</phase>
                        <goals>
                            <goal>zipalign</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>release</id>
            <!-- via this activation the profile is automatically used when the release 
                is done with the maven release plugin -->
            <activation>
                <property>
                    <name>performRelease</name>
                    <value>true</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jarsigner-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>signing</id>
                                <goals>
                                    <goal>sign</goal>
                                    <goal>verify</goal>
                                </goals>
                                <phase>package</phase>
                                <inherited>true</inherited>
                                <configuration>
                                    <removeExistingSignatures>true</removeExistingSignatures>
                                    <archiveDirectory />
                                    <includes>
                                        <include>${project.build.directory}/${project.artifactId}.apk</include>
                                    </includes>
                                    <keystore>${sign.keystore}</keystore>
                                    <alias>${sign.alias}</alias>
                                    <storepass>${sign.storepass}</storepass>
                                    <keypass>${sign.keypass}</keypass>
                                    <verbose>false</verbose>
                                    <arguments>
                                        <argument>-sigalg</argument>
                                        <argument>MD5withRSA</argument>
                                        <argument>-digestalg</argument>
                                        <argument>SHA1</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- the signed apk then needs to be zipaligned and we activate proguard 
                        and we run the manifest update -->
                    <plugin>
                        <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                        <artifactId>android-maven-plugin</artifactId>
                        <inherited>true</inherited>
                        <configuration>
                            <release>true</release>
                            <sign>
                                <debug>false</debug>
                            </sign>
                            <zipalign>
                                <skip>false</skip>
                                <verbose>true</verbose>
                                <inputApk>${project.build.directory}/${project.artifactId}.apk</inputApk>
                                <outputApk>${project.build.directory}/${project.artifactId}-signed-aligned.apk
                                </outputApk>
                            </zipalign>
                            <manifest>
                                <debuggable>false</debuggable>
                                <versionCodeAutoIncrement>true</versionCodeAutoIncrement>
                            </manifest>
                            <!-- Change to true to skip Proguard -->
                            <proguard>
                                <skip>false</skip>
                                <config>proguard.conf</config>
                            </proguard>
                        </configuration>
                        <executions>
                            <execution>
                                <id>manifestUpdate</id>
                                <phase>process-resources</phase>
                                <goals>
                                    <goal>manifest-update</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>alignApk</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>zipalign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${project.build.directory}/${project.artifactId}-signed-aligned.apk</file>
                                    <type>apk</type>
                                    <classifier>signed-aligned</classifier>
                                </artifact>
                                <artifact>
                                    <file>${project.build.directory}/proguard/mapping.txt</file>
                                    <type>map</type>
                                    <classifier>release</classifier>
                                </artifact>
                            </artifacts>
                        </configuration>
                        <executions>
                            <execution>
                                <id>attach-signed-aligned</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>attach-artifact</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

服务器 - 它pom:

<?xml version="1.0" encoding="UTF-8"?>
<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>de.e-nexus</groupId>
        <artifactId>zopp.server-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>zopp.server-it</artifactId>
    <packaging>apk</packaging>
    <name>zopp.server-it - Integration tests</name>

    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android-test</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>de.e-nexus</groupId>
            <artifactId>zopp.server</artifactId>
            <type>apk</type>
            <version>0.0.1-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>de.e-nexus</groupId>
            <artifactId>zopp.server</artifactId>
            <type>jar</type>
            <version>0.0.1-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <configuration>
                    <test>
                        <!--<skip>true|false|auto</skip> -->
                        <!--<instrumentationPackage>packageName</instrumentationPackage> -->
                        `
                        <!--<instrumentationRunner>className</instrumentationRunner> -->
                        <!--<debug>true|false</debug> -->
                        <!--<coverage>true|false</coverage> -->
                        <!--<logonly>true|false</logonly> avd -->
                        <!--<testsize>small|medium|large</testsize> -->
                        <createReport>true</createReport>
                        <!--<classes> -->
                        <!--<class>your.package.name.YourTestClass</class> -->
                        <!--</classes> -->
                        <!--<packages> -->
                        <!--<package>your.package.name</package> -->
                        <!--</packages> -->
                    </test>
                    <sdk>
                        <platform>10</platform>
                    </sdk>
                                    </configuration>
                <extensions>true</extensions>
            </plugin>
        </plugins>
    </build>
</project>

服务器父pom

<?xml version="1.0" encoding="UTF-8"?>
<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>
        <artifactId>android.zopp</artifactId>
        <groupId>de.e-nexus</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>zopp.server-parent</artifactId>
    <packaging>pom</packaging>
    <name>zopp.server - Parent</name>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.google.android</groupId>
                <artifactId>android</artifactId>
                <version>${platform.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>com.google.android</groupId>
                <artifactId>android-test</artifactId>
                <version>${platform.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.11</version>
                <scope>provided</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-jarsigner-plugin</artifactId>
                    <version>1.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>2.6</version>
                    <configuration>
                        <encoding>UTF-8</encoding>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                    <artifactId>android-maven-plugin</artifactId>
                    <version>${android.plugin.version}</version>
                    <configuration>
                        <sdk>
                            <platform>10</platform>
                        </sdk>
                        <zipalign>
                            <verbose>true</verbose>
                        </zipalign>
                        <undeployBeforeDeploy>true</undeployBeforeDeploy>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>build-helper-maven-plugin</artifactId>
                    <version>1.8</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <profiles>
        <profile>
            <!-- the standard profile runs the instrumentation tests -->
            <id>standard</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <modules>
                <module>zopp.server</module>
                <module>zopp.server-it</module>
            </modules>
        </profile>
        <profile>
            <!-- the release profile does sign, proguard, zipalign ... but does not 
                run instrumentation tests -->
            <id>release</id>
            <!-- via this activation the profile is automatically used when the release 
                is done with the maven release plugin -->
            <activation>
                <property>
                    <name>performRelease</name>
                    <value>true</value>
                </property>
            </activation>
            <modules>
                <module>zopp.server</module>
            </modules>
        </profile>
    </profiles>

    <modules>
        <module>zopp.server</module>
        <module>zopp.server-it</module>
    </modules>
</project>

根pom:

<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>de.e-nexus</groupId>
    <artifactId>android.zopp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <platform.version>2.3.3</platform.version>
        <android.plugin.version>3.8.2</android.plugin.version>
    </properties>
    <modules>
        <module>zopp.server</module>
        <module>zopp.client</module>
        <module>zopp.api</module>
    </modules>
    <build>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
            </plugin>
        </plugins>
    </build>
</project>

0 个答案:

没有答案