The problem of maven using profile to rely on packages in idea

< H1 > problem description < / H1 >

maven projects in idea use profile to manage dependencies that need to be introduced in different environments

uses two profile, one for activemq, and the other for kafka, and each of these dependencies introduces the dependency you need.

but when activating one of the profile, such as activemq, the kafka in the project will report an error

< H1 > Code < / H1 >
<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>

as in the above code, there is no problem with compiling and running the code on the command line, you just need to specify profile.

however, in intellji idea, the code in the kafka in the project will report an error because the content introduced has no related dependencies.

Menu