1

Maven Web アプリケーションがあります。これはビルドに時間がかかりすぎます (30 ~ 40 分)。10 分未満に短縮したいと考えています。私の pom.xml は以下の通りです。

<?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>se.mysite.etc.settings</groupId>
        <artifactId>projects</artifactId>
        <version>1.5</version>
    </parent>
    <groupId>se.myweb.portal</groupId>
    <artifactId>myweb-se-main</artifactId>
    <name>myweb-se-main</name>
    <version>3.1.81-B2_forv-SNAPSHOT</version>
    <packaging>pom</packaging>
    <inceptionYear>2009</inceptionYear>
    <properties>
        <release.version>${project.version}</release.version>
        <acc.version>2.3.42-TEST-MAINT-SNAPSHOT</acc.version>
        <cxf.version>2.5.3</cxf.version>
        <spring.version>3.0.3.RELEASE</spring.version>
        <spring.security.version>2.0.4</spring.security.version>
        <spring.webflow.version>2.1.1.RELEASE</spring.webflow.version>
        <commonportal.version>1.9.9-SPRING3</commonportal.version>          
        <junit.version>4.5</junit.version>
        <java.source.version>1.6</java.source.version>
        <cobertura.maxmem>1024M</cobertura.maxmem>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <scm>
        <connection>scm:hg:http://test1/myweb</connection>
        <developerConnection>scm:hg:http://test1/myweb</developerConnection>
        <tag/>
        <url>http://test1/myweb</url>
    </scm>
    <profiles>
        <profile>
            <id>dev</id>
            <dependencies>
                <!--some dependencies-->
            </dependencies>
            <modules>
                <module>../project1</module>
                <module>../project2</module>
                <module>../project3</module>
                <module>../project4</module>
            </modules>
        </profile>
        <profile>
            <id>dist</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <dependencies>
                <!--some dependencies-->
            </dependencies>
            <modules>
                <module>../project1</module>
                <module>../project2</module>
                <module>../project3</module>
                <module>../project4</module>
                <module>../project5</module>
                <module>../project6</module>
            </modules>
        </profile>
        <profile>
            <id>backend</id>
            <dependencies>
                <!--some dependencies-->
            <modules>
                <module>../project3</module>
                <module>../project1</module>
                <module>../project2</module>
                <module>../project4</module>
                <module>../project9</module>
            </modules>
        </profile>
        <profile>
            <id>frontend</id>
            <!--some dependencies-->
            <modules>
                <module>../project10</module>
                <module>../project11</module>
            </modules>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.12.4</version>
                        <configuration>
                            <forkMode>always</forkMode>
                            <argLine>-Xms512m -Xmx2048m -XX:MaxPermSize=2048m</argLine>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>webtest</id>
            <build>
                <finalName>myweb-web-test</finalName>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <argLine>-XX:MaxPermSize=512m</argLine>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
            <!--some dependencies-->
            <modules>
                <module>../myweb-web-test</module>
            </modules>
        </profile>
        <profile>
            <id>redeploy_web_app</id>
            <activation>
                <property>
                    <name>redeployWebApp</name>
                </property>
            </activation>
            <properties>
                <user.tomcat.home>${env.DEST_DIR}</user.tomcat.home>
            </properties>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-antrun-plugin</artifactId>
                            <version>1.6</version>
                            <dependencies>
                                <!--some dependencies-->
                            </dependencies>
                            <executions>
                                <execution>
                                    <id>delete_project_artifact</id>
                                    <phase>prepare-package</phase>
                                    <configuration>
                                        <tasks>
                                            <taskdef classpathref="maven.plugin.classpath" resource="net/sf/antcontrib/antcontrib.properties"/>
                                            <if>
                                                <equals arg1="${project.packaging}" arg2="war"/>
                                                <then>
                                                    <echo message="Removing ${project.artifactId}.${project.packaging} from ${user.tomcat.home}/webapps"/>
                                                    <delete dir="${user.tomcat.home}/webapps/${project.artifactId}"/>
                                                    <delete file="${user.tomcat.home}/webapps/${project.artifactId}.${project.packaging}"/>
                                                </then>
                                            </if>
                                        </tasks>
                                    </configuration>
                                    <goals>
                                        <goal>run</goal>
                                    </goals>
                                </execution>
                                <execution>
                                    <id>copy_project_artifact</id>
                                    <phase>package</phase>
                                    <configuration>
                                        <tasks>
                                            <taskdef classpathref="maven.plugin.classpath" resource="net/sf/antcontrib/antcontrib.properties"/>
                                            <if>
                                                <equals arg1="${project.packaging}" arg2="war"/>
                                                <then>
                                                    <echo message="Copying ${project.build.finalName}.${project.packaging}"/>
                                                    <copy file="${project.build.directory}/${project.build.finalName}.${project.packaging}" overwrite="true" tofile="${user.tomcat.home}/webapps/${project.artifactId}.${project.packaging}"/>
                                                </then>
                                            </if>
                                        </tasks>
                                    </configuration>
                                    <goals>
                                        <goal>run</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    <!-- General dependencies -->


    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <instrumentation>
                        <excludes>
                            <exclude>se.mysite/**/Test*.class</exclude>
                        </excludes>
                    </instrumentation>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <!-- TODO: Use UTF-8 here or not??? -->
                    <encoding>UTF-8</encoding>
                    <!-- encoding>ISO-8859-1</encoding-->
                    <source>${java.source.version}</source>
                    <target>${java.source.version}</target>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <scmCommentPrefix>II    Release:</scmCommentPrefix>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <organization>
        <name>mysite AB</name>
        <url>http://www.mysite.se</url>
    </organization>
</project>

私のコンパイルコマンドは以下です。

mvn -U -DartifactsTarget=$DEST_DIR/lib/tpp -P dev -Dmaven.test.failure.ignore=true -Dtesting.testsToExclude=**/Test*.java -f pom.xml $* -DredeployWebApp install

ビルドには約 30 分かかります。

私はMaven 3.0.4を使用しています。次のオプションを使用して、ビルド時間を最適化できることを調査しました。

  1. Maven 並列処理の使用
  2. 神経叢コンパイラプラグインの使用
  3. Mavenパワーシェルの使用

pom.xml に他の変更が必要かどうか、またはパフォーマンスを最適化する他の手法が必要かどうかをお知らせください。

4

1 に答える 1

5

Java プロジェクトの Maven ビルドの最適化は、次の 3 つの要因に帰着します。

  1. コンパイルとテスト
  2. Maven ビルドの複雑さ
  3. Maven (バイナリ) のパフォーマンスの最適化

コンパイルとテスト

たとえば、アプリケーションに GWT があり、20 の異なる順列をコンパイルしている場合、これをずっと実行していると問題になります。

必要なときにのみ完全なビルドを実行し、それ以外の場合はdraftCompileまたはoptimizationLevelオプションを使用してビルドを制限することで、これを回避する方法があります。

同じことがテストにも当てはまります。何百ものテストがある場合、各テストにかかる時間はかなり長くなります。テストのパフォーマンスを向上させる一般的な方法は次のとおりです。

  1. を使用しないでくださいThread.sleep(..)。ミューテックスとロックを使用してください。
  2. テストごとにセットアップを行うのではなく、複数のテストで構成 (永続化ユニット、モック) を共有します。
  3. 本当に必要でない限り、統合テストではなく単体テストにしてください。いずれにせよ、統合テストが多すぎるのはコードの悪臭です。

Maven ビルドの複雑さ

複雑な依存関係ツリーを持つ数十または数百のモジュールがある場合、maven は依存関係ツリーを計算するのに時間がかかります。`dependency:analyze' を使用して、未使用の依存関係があるかどうかを調べ、それらを削除します。

また、各モジュールのビルドで使用されるプラグインの数によって、ビルド時間が長くなります。

Maven (バイナリ) のパフォーマンスの最適化

次のオプションを使用します。

export MAVEN_OPTS="-Dmaven.wagon.provider.http=httpclient -Dmaven.artifact.threads=12 -Dhttp.tcp.nodelay=false -Xmx2048M -Xss256M -XX:+CMSClassUnloadingEnabled -XX:-UseGCOverheadLimit -XX:MaxPermSize=256M -T2C"

  • -Dmaven.wagon.provider.http=httpclient: http 接続メカニズムを変更します。私の理論では、Apache HttpClient ライブラリはデフォルトの JavaHttpURLConnectionクラスよりも高速で優れています。
  • -Dmaven.artifact.threads=12: アーティファクトのダウンロードに使用されるスレッドの数。
  • -Dhttp.tcp.nodelay=false: Nagle のアルゴリズムをオフにして、パフォーマンスを向上させます (帯域幅も使用します)。ワゴン物件です。
  • -T2C: これは maven 3 で導入された期限切れのビルドでした: ビルドごとのスレッド数。Maven 3 での並列ビルドを参照してください。

他のヒントがあれば、この投稿を編集してください。

于 2015-11-11T12:30:11.797 に答える