Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Please note that all plugin configurations described in the follow-up sections are placed into <profiles/> section of POM

Code Block
xml
xml
titlepom.xml/profilesxml
<project>
...
    <profiles>
        <profile>
            <id>build</id>
            <build>
                <plugins>
                   <!-- Plugins configuration here -->
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

...

The dependencies are configured in child POM only. Since dependencies stored as ZIP files we cannot use common dependency mechanism provided by Maven. Instead we are using maven-dependency-plugin unpack artifact feature. Here's complete configuration from FOO/CalendarView project that defines dependency on FOO/ReadCalendar. Note that we have ability to specify a particular version

Code Block
xml
xml
titleCalendarView/pom.xmlxml
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>unpack</id>
            <phase>process-resources</phase>
            <goals>
                <goal>unpack</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>mycompany.dept.foo</groupId>
                        <artifactId>ReadCalendar</artifactId>
                        <version>1.0-SNAPSHOT</version>
                        <type>zip</type>
                        <outputDirectory>${project.basedir}/lib</outputDirectory>
                        <overWrite>true</overWrite>
                    </artifactItem>
                </artifactItems>
            </configuration>
        </execution>
    </executions>
</plugin>

...

  • Define plugin maven-dependency-plugin
  • Define plugin's execution with ID = unpack
  • Execution will happen in Maven's process-resources lifecycle phase
  • Plugin's unpack goal will be executed
  • The goal will get specified artifactItem from Maven repo (the ZIP file) and exctract it into PROJECT_ROOT/lib directory
  • To make your .NET code aware of extracted artifact(s) update <HintPath/> for each dependency in you Foo.csproj file
    Code Block
    xml
    xml
    titlefoo.csprojxml
    <Reference Include="ReadCalendar, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
        <SpecificVersion>False</SpecificVersion>
        <HintPath>..\lib\ReadCalendar.dll</HintPath>
    </Reference>
    

...

This is "the meat" of the whole process. The configuration is split between the parent POM and child(ren) in such way that parent POM contains (in majority of cases) complete definition of profile(s) which keeps children POMs clean from repeatable code.
To suppress execution of profile in the parent you always need to execute parent-based build with --resume-from or -rf switch

Code Block
xml
xml
titleParent pom.xmlxml
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <configuration>
        <executable>${dotnet.path}/msbuild</executable>
    </configuration>
    <executions>
        <execution>
            <id>clean</id>
            <phase>clean</phase>
            <configuration>
                <arguments>
                    <argument>/p:Configuration=${foo.config}</argument>
                    <argument>/p:Platform=${foo.cpu}</argument>
                    <argument>/t:Clean</argument>
                </arguments>
            </configuration>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
        <execution>
            <id>build</id>
            <phase>compile</phase>
            <configuration>
                <arguments>
                    <argument>/p:Configuration=${foo.config}</argument>
                    <argument>/p:Platform=${foo.cpu}</argument>
                    <argument>/t:Build</argument>
                </arguments>
            </configuration>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
</plugin>

...

Step 1 is to scan project for build artifacts and collecting these to lib directory. It's done by maven-antrun-plugin. Here's configuration

Code Block
xml
xml
titleParent pom.xmlxml
<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.3</version>
    <configuration>
        <tasks>
            <copy todir="${project.build.directory}/dll-staging">
                <fileset dir="${basedir}">
                    <include name="**/*in/${foo.config}/*.dll" />
                    <include name="**/*in/${foo.config}/*.pdb" />
                    <include name="**/*in/${foo.config}/*.exe" />
                    <exclude name="**/Test*" />
                    <exclude name="**/test*" />
                </fileset>
                <flattenmapper />
            </copy>
        </tasks>
    </configuration>
    <executions>
        <execution>
            <id>copy</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

...

This is done by maven-assembly-plugin

Code Block
xml
xml
titleParent pom.xmlxml
<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
        <descriptors>
            <descriptor>../assembly.xml</descriptor>
        </descriptors>
    </configuration>
    <executions>
        <execution>
            <id>zip</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>
Code Block
xml
xml
titleassembly.xmlxml
<assembly>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>${project.build.directory}/dll-staging</directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>*.dll</include>
                <include>*.exe</include>
                <include>*.pdb</include>
            </includes>
            <excludes>
                <exclude>Test*</exclude>
                <exclude>test*</exclude>
            </excludes>
        </fileSet>
    </fileSets>
</assembly>

...