The following contains summary of all available goals in native-maven-plugin. They work together in a Maven custom build lifecycle
Native plugin supports the following packaging types:
One of these packaging types will go into the your pom.xml's packaging element.
The native build lifecyle uses packaging type as the extension of the build artifact( ie dll, exe, lib, etc ). However, it has minimal knowledge to build each specific extension. You must configure appropriate compiler/linker options at build phase.
"uexe" is a place holder for executable without extension name usually found on UNIX environment. The final artifact will have extension of "uexe".
Since this plugin uses its own lifecycle, you need to enable plugin's extensions to true
Here is example of declaring your packaging type and plugin header
<project> ... <packaging>so</packaging> ... <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>native-maven-plugin</artifactId> <extensions>true</extensions> <configuration> ... </configuration> </plugin> </plugins> </build>
Internally, this plugin copies all dependencies to ${project.build.directory}/lib without the version tag.
The following example shows 2 .so dependency files, and other files in linker option to be linked to the final output file.
<project> ... <dependencies> <dependency> <groupId>someGroup</groupId> <artifactId>someId</artifactId> <version>someVersion</version> <type>so</type> </dependency> <dependency> <groupId>someGroup</groupId> <artifactId>someId2</artifactId> <version>someVersion<version> <type>so</type> </dependency> <dependency> <groupId>someGroup</groupId> <artifactId>someId2</artifactId> <version>someVersion<version> <type>inczip</type> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>native-maven-plugin</artifactId> <extensions>true</extensions> <configuration> .... <linkerStartOptions> <linkerStartOption>-shared -lxml2 -lz -lpthread -ldl</linkerStartOption> </linkerStartOptions> </configuration> </plugin> </plugins> </build>
Include paths and source files are configured using Source configuration. The following example shows a set of compilable source files consist of:
Include paths consist of all <directory> under <sources>
<build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>native-maven-plugin</artifactId> <extensions>true</extensions> <configuration> ..... <sources> <source> <-- relative to your project directory --> <directory>../src/main/native</directory> <!-- ant base wild card files> <includes> <include>**/*.cpp</include> </includes> <excludes> <exclude>somefile.cpp</exclude> </excludes> <fileNames> <fileName>file1.c</fileName> <fileName>file2.c</fileName> </fileNames> </source> <source> <directory>src/main/native</directory> <fileNames> <fileName>file3.c</fileName> <fileName>file4.c</fileName> <fileName>...</fileName> </fileNames> </source> <!-- additional include path --> <source> <directory>...</directory> <!-- use this to have maven deploying header files with a .inzip type --> <!-- typically used to for library artifacts header files ---> <deployable>true</deployable> </source> <!-- additional system include path --> <source> <directory>...</directory> <dependencyAnalysisParticipation>false</dependencyAnalysisParticipation> </source> </sources> .... </configuration> </plugin> </plugins> </build>
If you are on a UNIX system, use the default generic, or generic-classic but overwrite compilerExecutable and linkerExecutable configuration specific to your build. Default values for both generic compiler and linker are "gcc". Ensure the executables are on your path.
On Windows, use Windows supported compiler and linker such as "msvc" and "bcc"
Each provided compiler/linker provider assumes minimal knowledge of available options. The following contains a list of options that will be automatically injected to final command lines:
Other notes:
The following example use generic-classic with executable as CC. Note since we dont change the linker provider, it is will use the same name as the compiler provider name.
<build> <plugins> <plugin> ... <configuration> <compilerProvider>generic-classic</compilerProvider> <compilerExecutable>CC</compilerExecutable> .... </configuration> </plugin> </plugins> </build>
You can inject your specific compiler and linker arguments to the final compiler and linker command lines via:
Usually a pair of <compilerStartOptions> and <linkerStartOptions> should be sufficient.