如何使用不同版本的库运行单元测试而不手动更改它?

发布于 2024-12-29 21:40:19 字数 226 浏览 6 评论 0原文

单元测试是用Java编写的,使用Maven来构建&跑步。我可以使用 Maven“外部”的本地 jar 或本地 Maven 存储库。

但是,我想找出一种方法以某种方式自动执行此操作,而不更改 pom.xml-> 运行 -> 更改 pom.xml

除了上述方法或创建 pom.xml 之外,还有其他方法吗?特定库版本有何不同?

(如果有用的话我正在使用 IntelliJ)

Unit test is in Java, using Maven to build & run. I can use either local jars "outside" Maven or local Maven repository.

However, I'd like to figure out a way to do this automatically somehow, without changing the pom.xml->running ->changing the pom.xml

Is there any other way except the above or creating pom.xmls which only differ in the specific library version?

(I'm using IntelliJ if that's of any use)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

对不⑦ 2025-01-05 21:40:19

您还可以从属性中读取库的版本,例如

    <dependency>
        <groupId>javax.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>${jsp.api.version}</version>
    </dependency>

您可以通过多种方式设置此属性,例如加载特定于构建的属性文件。

您甚至可以在运行构建时将其指定为参数。在命令行 svn 上,这就像

 mvn -Djsp.api.version=1.8 install

Don't Know how to指定这样的属性当从 IntelliJ 内部运行 Maven 时,但我确信这是可能的......

这种方法将为您提供充分的灵活性,可以自由地指定 lib每个版本的版本。但是,如果您想要选择的版本数量有限,那么使用配置文件可能是更好的方法。只需为每个版本号定义一个配置文件,并始终告诉 Maven 在运行构建时使用哪个配置文件。

You could also read the version of your lib from a property, like

    <dependency>
        <groupId>javax.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>${jsp.api.version}</version>
    </dependency>

You can set this property in several ways, e.g. loading build-specific properties file.

You could even specify it as a parameter when running the build. On the command line svn, this is something like

 mvn -Djsp.api.version=1.8 install

Don't know how to specify such an property when running Maven from inside IntelliJ, but I'm sure it's possible....

This approach would give you full flexibility to freely speficy the lib version for each build. But if you only have a limited number of versions you want to choose from, using profiles is probably the better way to go. Just define a profile for each version number and the always tell Maven which profile to use when you run a build.

夜司空 2025-01-05 21:40:19

您正在寻找的是 Maven 中的 profiles 以及 properties

您可以使用 property 来指定版本号,并且可以使用 profiles 来指定该属性的实际内容,然后指定运行 Maven 时要使用的配置文件。

What you are looking for is profiles in Maven with properties.

You use a property to specify the version number and you can use profiles to specify what the property actually is and then specify which profile to use when you run Maven.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文