在 C/C + + 项目中使用 Maven

我将 Maven 构建围绕业余的、编写糟糕的、坦率地说是原始的 C/C + + 代码集群(意味着一些 C,一些 C + +)。问题是,现在流通中有很多这样的东西,而且不容易被替代。构建它需要大量的专业知识(你必须从一个立方体转到另一个立方体,才能知道如何编译/构建各种各样的部件) ,而发布则是彻头彻尾的噩梦。(不,我不会重写的,请不要问) 我的问题是-我应该使用 maven-native-plugin来替换大量的短 makefile 还是使用 exec-maven-plugin来简单地执行这些? 到目前为止,我有 相当不错的经历和后者做。NET,不知道我是否应该投资到 native插件或留与 exec?如果你有使 C/C + + “最大化”的经验,我很乐意得到一些建议。

83455 次浏览

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.

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