maven build需要太多时间

时间:2012-08-06 02:29:02

标签: maven

据我所知,Maven只编译修改后的文件并将其复制到目标文件夹中。

在我的webapp文件夹中,有大量文件超过 800MB

当我启动此命令(mvn包)时。

这需要超过 10分钟才能将所有资源复制到target / icall /

[INFO]复制webapp资源[/ data1 / workspace / icall / src / main / webapp]

这让我很恼火。

有没有办法只复制修改过的文件或新生成的文件?

<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>
    <groupId>com.byto</groupId>
    <artifactId>icall</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>icall Maven Webapp</name>
    <url>http://maven.apache.org</url>

    <build>
        <finalName>icall</finalName>

        <resources>
            <resource>
                <directory>${basedir}/src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <escapeString>\</escapeString>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.7</version>
                <configuration>
                    <additionalProjectnatures>
                        <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                    </additionalProjectnatures>
                    <additionalBuildcommands>
                        <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
                    </additionalBuildcommands>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                    <wtpversion>1.5</wtpversion>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>

        </plugins>
    </build>

    <profiles>
        <!-- Unrelated Profiles -->
    </profiles>

    <properties>
        <spring-version>3.1.1.RELEASE</spring-version>
        <tiles-version>2.2.2</tiles-version>
        <mybatis-version>3.1.1</mybatis-version>
    </properties>

    <dependencies>
         <!-- Lots of Unrelated Dependencies -->
    </dependencies>

</project>

这是我使用的linux bash文件,而不是Package或Install目标。但我不能使用作为maven主要功能的依赖管理。但这对我来说仍然有用。

#! /bin/sh

tomcat_path=/usr/local/tomcat
source_path=/data1/workspace/icall
deploy_path=/data1/icall_root

function refresh_source {
    # Update source from SVN
    echo -e "\n\n** Getting new sources from SVN." &&
    svn update &&

    # Compile *.java
    echo -e "\n\n** Building *.java with Maven." &&
    mvn compile -Pdev &&

    # Copy only modified files
    echo -e "\n\n** copying files from ${source_path}/src/main/webapp to ${deploy_path}." &&
    rsync -av --exclude=.svn --exclude=WEB-INF/lib/* --exclude=WEB-INF/classes/* --delete ${source_path}/src/main/webapp/* ${deploy_path}/ &&

    echo -e "\n\n** copying files from ${source_path}/library to ${deploy_path}/WEB-INF/lib." &&
    rsync -av --delete --delete-excluded ${source_path}/library/* ${deploy_path}/WEB-INF/lib/ &&

    echo -e "\n\n** copying files from ${source_path}/target/classes/ to ${deploy_path}/WEB-INF/classes/"
    rsync -av --checksum --delete --delete-excluded ${source_path}/target/classes/* ${deploy_path}/WEB-INF/classes/ &&

    ## Only for development server
    cp -f ${deploy_path}/info.jsp ${deploy_path}/data/info.jsp
}

function tomcat_restart {
        ${tomcat_path}/bin/shutdown.sh &&
        sleep 30 &&
        ${tomcat_path}/bin/startup.sh
}

case "$1" in
    restart)
        refresh_source &&
        tomcat_restart
        ;;
    log)
        tail -f ${tomcat_path}/logs/catalina.out
        ;;
    *)
        refresh_source
        ;;
esac

2 个答案:

答案 0 :(得分:0)

您可以创建一个额外的工件,它只包含那些大型资源文件。在预包装阶段,工件将仅驻留在本地存储库中。例如,如果您需要将该工件放在war文件中,则无法避免在打包阶段进行复制。但是你可以尝试不把它放在战争中并将其保留为另一个文件,这应该是类路径上的额外文件。但这可能会导致更复杂的部署方案。

答案 1 :(得分:0)

我发现排除最终战争中不需要的文件会加快构建速度。另请参阅此答案https://stackoverflow.com/a/41452761/225341

相关问题