workerjoe
workerjoe

Reputation: 2645

Can I set lifecycle phase in the Maven pom.xml `<resources>` element?

In my POM I have a <resources> section inside <build>. This appears to be a shorthand for the maven-resources-plugin, I guess. It doesn't go in the <plugins> section. I'd like to do some resource filtering in the generate-sources lifecycle phase, which is not the default, so I tried to add a <phase> element.

It doesn't work; I get "Malformed POM ... Unrecognized tag: 'phase'".

The POM structure I'm trying is like this:

<project>
...
<build>
    <resources>
        <resource>
           <directory>src</directory>
           <filtering>true</filtering>
           <phase>generate-sources</phase>
        </resource>
    </resources>
    <plugins>
        ...
    <plugins>
</build>
</project>

Is there a way to accomplish this in the "build->resources" element, or do I need to configure the plugin in the "plugins" element?

Upvotes: 0

Views: 29

Answers (1)

J Fabian Meier
J Fabian Meier

Reputation: 35785

You cannot add a <phase> to the <resources> section, but you can add it to the maven resources plugin by mentioning it explicitly in your POM like

 <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.3.1</version>
...

Upvotes: 0

Related Questions