如何基于所选IntelliJ Profile激活对应Maven Profile?
基于IntelliJ Profile自动激活对应Maven Profile配置方案
需求背景
需要根据所选的IntelliJ运行Profile,自动激活对应的Maven Profile,实现本地测试和服务器部署时加载不同版本的TimesTen依赖:
- 本地测试:激活
localMaven Profile,使用TimesTen 6版本 - 构建部署:激活
serverMaven Profile,使用TimesTen 11版本
已配置的Maven Profile
<profiles> <profile> <id>local</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <org.timesten.version>6</org.timesten.version> </properties> </profile> <profile> <id>server</id> <properties> <org.timesten.version>11</org.timesten.version> </properties> </profile> </profiles>
IntelliJ配置步骤
IntelliJ Profile截图说明:界面包含两个自定义运行Profile(
Local和Server),需为每个Profile绑定对应Maven Profile
- 打开IntelliJ的运行/调试配置(Run/Debug Configurations)
- 选中目标IntelliJ运行Profile(如
Local) - 切换到构建和运行(Build and run)标签页,找到Maven配置项
- 在Profiles输入框中填入
local,保存配置 - 重复上述步骤,为
Server运行Profile的Profiles输入框填入server
完成配置后,启动对应IntelliJ运行Profile时,Maven会自动激活指定的Profile,加载对应版本的TimesTen依赖。
内容的提问来源于stack exchange,提问作者Jakub Znamenáček
相关产品推荐
相关产品推荐

