如何使用不同版本的库运行单元测试而不手动更改它?
单元测试是用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还可以从属性中读取库的版本,例如
您可以通过多种方式设置此属性,例如加载特定于构建的属性文件。
您甚至可以在运行构建时将其指定为参数。在命令行 svn 上,这就像
Don't Know how to指定这样的属性当从 IntelliJ 内部运行 Maven 时,但我确信这是可能的......
这种方法将为您提供充分的灵活性,可以自由地指定 lib每个版本的版本。但是,如果您想要选择的版本数量有限,那么使用配置文件可能是更好的方法。只需为每个版本号定义一个配置文件,并始终告诉 Maven 在运行构建时使用哪个配置文件。
You could also read the version of your lib from a property, like
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
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.
您正在寻找的是 Maven 中的
profiles
以及properties
。您可以使用
property
来指定版本号,并且可以使用profiles
来指定该属性的实际内容,然后指定运行 Maven 时要使用的配置文件。What you are looking for is
profiles
in Maven withproperties
.You use a
property
to specify the version number and you can useprofiles
to specify what the property actually is and then specify which profile to use when you run Maven.