用Maven下载所有依赖、插件依赖、编译器等?

7

我正在制作一个Docker镜像,该镜像在运行时执行Maven任务。它看起来有点像这样:

ADD pom.xml /srv
ADD src /srv/src

WORKDIR /srv
RUN mvn dependencies:go-offline scala:testCompile

在运行时,我正在运行mvn gatling:execute来运行一个负载测试工具。

我的POM文件如下:

<project>
  <dependencies>
        <dependency>
            <groupId>io.gatling</groupId>
            <artifactId>gatling-core</artifactId>
            <version>${gatling.version}</version>
        </dependency>
        <dependency>
            <groupId>io.gatling</groupId>
            <artifactId>gatling-http</artifactId>
            <version>${gatling.version}</version>
        </dependency>
        <dependency>
            <groupId>io.gatling</groupId>
            <artifactId>gatling-app</artifactId>
            <version>${gatling.version}</version>
        </dependency>
        <dependency>
            <groupId>io.gatling.highcharts</groupId>
            <artifactId>gatling-charts-highcharts</artifactId>
            <version>${gatling.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>${scala-maven-plugin.version}</version>
            </plugin>
            <plugin>
                <groupId>io.gatling</groupId>
                <artifactId>gatling-maven-plugin</artifactId>
                <version>${gatling-plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

我希望的是,当我最终运行mvn gatling:execute时,不需要下载任何依赖项,而是想在构建时将它们全部打包到镜像中。
然而,即使执行mvn dependencies:go-offline scala:testCompile也不能完全满足我的需求。运行gatling:execute仍然需要下载更多的依赖项。
如何在Docker镜像中下载Maven所需的所有内容,以便在运行时不需要进行任何下载?

你有什么建议?抱歉,今天很长,我不确定你的意思是什么。 - Naftuli Kay
类似这样的代码 <execution><phase>integration-test</phase><goals><goal>execute</goal></goals></execution>。 - Trent Bartlem
问题在于我无法运行 gatling:execute 而不会大规模攻击一个端点 ;) - Naftuli Kay
这是可以理解的,但如果您没有超过mvn package阶段,那就不是问题。无论如何,如果Gatling依赖项被绑定到某个阶段,maven依赖项插件是否找到了它们呢? - Trent Bartlem
@NaftuliTzviKay,你的目标是什么?你想分发这个镜像(例如在公司内部),还是想将其用作构建环境,并且不想在每次构建时都下载相同的内容?如果是后者,你可以将你的Maven存储库目录放在Docker卷中。 - ivant
显示剩余5条评论
2个回答

1

您并不一定需要使用maven插件来运行模拟,是吗?您可以使用maven打包一个包含所有依赖项的jar文件,并从中执行gatling runner。


我知道。我需要一些_快速的_东西,我不想整天折腾maven汇编插件,试图正确地打包和运行Scala应用程序。 - Naftuli Kay

0

您可以使用以下命令下载所有依赖项:mvn dependency:copy-dependencies

执行完毕后,您的项目所有依赖项将会被下载到./target/dependency/文件夹中。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接