Using Maven for C/C++ projects

I highly recommend the maven-nar-plugin. I find it superior in many ways to the alternatives. It doesn’t require listing out source files, handles multiple OSes and architectures, handles unit and integration tests, and generally follows “the maven way”. It introduces a new kind of packaging – the NAR, or “native archive”, that contains the artifact you care about (.dll, .so, .a, .exe, etc.) but also metadata, headers, etc. in a way that makes sense.

It does require a bit of up front work to package third-party software up into NARs, but its pretty straightforward. Once they are NARs, you simply use the normal Maven dependency mechanism to link with them, for example:

<dependency>
  <groupId>cppunit</groupId>
  <artifactId>cppunit</artifactId>
  <scope>test</scope>
</dependency>

One drawback is that it does not appear to be actively maintained, but it is full-featured and is a rather impressive example of Maven plugin authoring.

Leave a Comment