'maven toolchain in profile

If I define toolchain plugin in activated by default profile it's not working for some plugin such as maven-javadoc-plugin(for maven-compiler-plugin it is working) :

<profile>
    <id>jdk-toolchain</id>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-toolchains-plugin</artifactId>
                <version>1.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>toolchain</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <toolchains>
                        <jdk>
                            <version>${project.javaVersion}</version>
                            <vendor>sun</vendor>
                        </jdk>
                    </toolchains>
                </configuration>
            </plugin>
        </plugins>
    </build>
</profile>

In other case it work perfect for all plugin:

<build>
    <plugins>
...
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-toolchains-plugin</artifactId>
                    <version>1.1</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>toolchain</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <toolchains>
                            <jdk>
                                <version>${project.javaVersion}</version>
                                <vendor>sun</vendor>
                            </jdk>
                        </toolchains>
                    </configuration>
                </plugin>
...
    </plugins>
</build>

Why is this happening?



Solution 1:[1]

you have to bind the execution of your plugin into validate phase:

<executions>
    <execution>
        <phase>validate</phase>
        <goals>
            <goal>toolchain</goal>
            </goals>
    </execution>
</executions>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eladio Mejuto