开发者

Declarative maven syntax/language, I don't understand duplicate build tags

开发者 https://www.devze.com 2023-02-21 06:28 出处:网络
I don\'t understand the duplicate grouping of tags that maven uses.I am more used to ant where the action or tasks are more explicit.With a maven pom file listed below,

I don't understand the duplicate grouping of tags that maven uses. I am more used to ant where the action or tasks are more explicit. With a maven pom file listed below,

Why is there a 'build' section within the profiles tag? And then towards the bottom is another set of 'build' section?

<profiles>
        <profile>
            <id>local</id>          
            <activation>
                <os>
                    <family>w开发者_StackOverflow社区indows</family>
                </os>
            </activation>
<build>
                <plugins>
                    <!-- Clean all jars before build -->
                    <plugin>
                        <artifactId>maven-clean-plugin</artifactId>

...

<build>
        <finalName>${project.artifactId}</finalName>
        <sourceDirectory>src</sourceDirectory>
        <testSourceDirectory>test</testSourceDirectory>
        <resources>
...
...
    <plugins>
            <!-- Compiler plugin -->
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${java.source.version}</source>
                    <target>${java.target.version}</target>
                </configuration>
            </plugin>

        </plugins>

    </build>
</project>


You seem to need to understand profiles.

A basic maven build has one (or zero) build elements. In the zero case, it will just apply the standard lifecycle to java sources and resources in the standard locations.

Profiles allow you to declare alternative builds with different settings. When you run 'mvn -Pfoo', you activate the profile named 'foo'.

You put a <build/> element in a profile when you wish to change the settings in the build element in that profile. For example, by changing the options passed to some plugin.

You asked, 'what does 'maven clean' do.

'clean' is the name of a lifecycle. You will find it documented at http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference.

The clean lifecycle has three phases. When you say 'mvn clean', it runs all the plugin executions that are bound to those three phases, in that order.

http://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Super_POM documents the super-pom, and so tells you what plugin executions are bound to those three phases by default.

0

精彩评论

暂无评论...
验证码 换一张
取 消