Профиль не выполняется в модуле, даже если он указан как активный профиль - PullRequest
0 голосов
/ 11 октября 2019

У меня есть следующий родительский элемент pom.xml, определяющий профиль foo:

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.example</groupId>
    <artifactId>maven-profiles-test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <profiles>
        <profile>
            <id>foo</id>
            <activation>
                <property>
                    <!-- profile is active as long as this property is absent -->
                    <name>!foo.profile</name>
                </property>
            </activation>
        </profile>
    </profiles>

    <modules>
        <module>maven-profiles-test-module</module>
    </modules>
</project>

И у меня есть pom.xml модуля maven-profiles-test-module:

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.example</groupId>
        <artifactId>maven-profiles-test</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>maven-profiles-test-module</artifactId>

    <profiles>
        <profile>
            <id>foo</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>generate-resources</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <tasks>
                                        <echo>Hello world!</echo>
                                    </tasks>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

Когда язапустите mvn package для родителя с пустым maven settings.xml, плагин maven-antrun-plugin не выполняется. Я не вижу, как Hello World! записывается в вывод сборки.

Однако вывод mvn help:active-profiles:

Active Profiles for Project 'org.example:maven-profiles-test:pom:0.0.1-SNAPSHOT':

The following profiles are active:

 - foo (source: org.example:maven-profiles-test:0.0.1-SNAPSHOT)



Active Profiles for Project 'org.example:maven-profiles-test-module:jar:0.0.1-SNAPSHOT':

The following profiles are active:

 - foo (source: org.example:maven-profiles-test:0.0.1-SNAPSHOT)

Так почему не выполняется maven-antrun-pluginв модуле?

Я использую:

Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T17:06:16+02:00)
Maven home: C:\Program Files\apache\apache-maven-3.6.2\bin\..
Java version: 1.8.0_161, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_161\jre
Default locale: de_DE, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...