账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    maven使用profile在idea中依赖包的问题
    62
    0

    问题描述

    idea中的maven项目使用了profile管理不同环境下需要引入的依赖

    使用了两种profile, 一个为activemq,另一个是kafka,而且这两种依赖都各自引入自己需要的dependency。

    但是当激活其中一个profile时,比如激活activemq时,项目中的kafka会报错

    代码

    <profiles>
            <profile>
                <id>kafka</id>
                <activation>
                    <activeByDefault>true</activeByDefault>
                </activation>
                <properties>
                    <active.profile>kafka</active.profile>
                </properties>
                <dependencies>
                    <dependency>
                        <groupId>org.springframework.kafka</groupId>
                        <artifactId>spring-kafka</artifactId>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework.kafka</groupId>
                        <artifactId>spring-kafka-test</artifactId>
                        <scope>test</scope>
                    </dependency>
                </dependencies>
                <build>
                    <resources>
                        <resource>
                            <directory>src/main/java/com/fw/sf/api/message/kafka</directory>
                            <excludes>
    
                            </excludes>
                        </resource>
                    </resources>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-compiler-plugin</artifactId>
                            <configuration>
                                <excludes>
                                    <exclude>com/fw/sf/api/message/activemq/*.java</exclude>
                                </excludes>
                            </configuration>
                        </plugin>
                    </plugins>
                </build>
            </profile>
            <profile>
                <id>activemq</id>
                <properties>
                    <active.profile>activemq</active.profile>
                </properties>
                <dependencies>
                    <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-activemq</artifactId>
                        <exclusions>
                            <exclusion>
                                <groupId>org.springframework</groupId>
                                <artifactId>spring-jms</artifactId>
                            </exclusion>
                        </exclusions>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.activemq</groupId>
                        <artifactId>activemq-pool</artifactId>
                    </dependency>
                </dependencies>
                <build>
                    <resources>
                        <resource>
                            <directory>src/main/java/com/fw/sf/api/message/kafka</directory>
                            <excludes>
    
                            </excludes>
                        </resource>
                    </resources>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-compiler-plugin</artifactId>
                            <configuration>
                                <excludes>
                                    <exclude>com/fw/sf/api/message/kafka/*.java</exclude>
                                </excludes>
                            </configuration>
                        </plugin>
                    </plugins>
                </build>
            </profile>

    如上面的代码,代码在命令行中编译运行都没有问题,只需要指明profile即可。

    但是,在intellji idea中,项目中kafka中的代码因为引入的内容没有相关依赖会报错。

    4
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部