91

I'm putting Maven build around cluster of amateur, poorly written and frankly - primitive C/C++ code (meaning some C, some C++). Problem is - there's lots of it in circulation currently and cannot be easily replaced. Building it requires a lot of tribal knowledge (you have to go from cube to cube just to find out how to compile/build various parts) and releasing is total nightmare. I'm not going to rewrite it, please don't suggest that.

Should I use maven-native-plugin to replace the multitude of short makefiles or use exec-maven-plugin to simply execute these? I had pretty good experience so far with the latter doing .NET and don't know if I should invest into native plugin or stay with exec? If you had experience with "Mavenizing" C/C++ I would love to get some advice.

Jeff Schaller
  • 2,352
  • 5
  • 23
  • 38
Bostone
  • 36,858
  • 39
  • 167
  • 227
  • I am just about to try it. As I see, it is still maintained and it has moved meanwhile here: http://github.com/sonatype/maven-nar-plugin – espakm Nov 04 '10 at 10:29

2 Answers2

94

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.

Dave
  • 21,524
  • 28
  • 141
  • 221
SingleShot
  • 18,821
  • 13
  • 71
  • 101
  • Thanks for the tip - I will definitely check it out! – Bostone Oct 09 '09 at 05:38
  • I'm going to accept this as answer - this indeed seems to be superior to maven-native-plugin – Bostone Oct 12 '09 at 18:45
  • 1
    Good luck. One thing to note - I received a notification this morning (how coincidental) that a bug I submitted a year ago was resolved today - maintenance appears to have reactived. – SingleShot Oct 12 '09 at 20:09
  • 2
    Looks like maven-nar-plugin is being activity maintained now by sonatype: https://issues.sonatype.org/browse/NAR – tommy chheng Apr 26 '11 at 22:52
  • It seems like there is quite smooth development on the Github https://github.com/maven-nar/maven-nar-plugin – Bartosz Firyn Jul 10 '13 at 15:58
  • yes the https://github.com/maven-nar/nar-maven-plugin looks promising I tried importing a project in intellij and adapting the groupId to 'com.github.maven-nar.its.nar' inorder to test individual tests, however the c++ tests failed, but general maven build and install worked - If the test and debugger for Cpp in intellij gets up and running, then this project definately becomes interesting - even boost libs are implemented using this maven plugin. If anybody have tried building tests for cpp and running this inside intellij with this maven plugin without issues, then please put a link here – serup Aug 15 '16 at 11:31
  • 1
    when using examples of nar-maven-plugin, then do following for it to work : mvn package -- this will generate the test packages and then it is possible to run test which depend on NarSystem – serup Aug 15 '16 at 11:58
1

To have an equivalent at Maven (Java). My advice is to use CMake + CPM for build and PKG management, most commun tools used in C++ world. As an alternative Gradle exist also for C++.

useful link: https://medium.com/swlh/cpm-an-awesome-dependency-manager-for-c-with-cmake-3c53f4376766

Chris Hess
  • 129
  • 3
  • In combination of Cmake, Instead of CPM you can also use VCPKG this link can help to compare PKG Manager for C++ https://jonathan.temno.eu/blog/vcpkg.html – Chris Hess Aug 08 '21 at 17:10
  • 2
    Why on earth did MS think it had to push a competitor to Conan, and why on earth did Mister Melchior think he should invent yet another tool, tied to one specific build system like CMake and even to one Git repo server (github only) ? At this rate, I can also propose to use build2's package manager, and if everyone continues this root, we'll have as many package managers as build systems as libraries as languages, making impossible to develop and distribute any software. – Johan Boulé Dec 31 '21 at 15:16