Maven project with native dependency and copying files

本秂侑毒 提交于 2019-11-30 14:34:22

I'd suggest turning the files into Maven modules, by installing them into the local repository using the Maven install plug-in

mvn install:install-file \
    -DgroupId=com.demo \
    -DartifactId=thirdpartylib \
    -Dversion=1.0 \
    -Dfile=thirdpartylib.jar

mvn install:install-file \
    -DgroupId=com.demo \
    -DartifactId=thirdpartylib-runtime \
    -Dversion=1.0 \
    -Dpackaging=dll
    -Dfile=thirdpartylib.dll

One of the neat things about this approach is that the Maven POM will be automatically generated.

The mylib project now declares the thirdparty modules as normal dependencies in it's POM file:

<dependencies>
    <dependency>
        <groupId>com.demo</groupId>
        <artifactId>thirdpartylib</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>com.demo</groupId>
        <artifactId>thirdpartylib-runtime</artifactId>
        <version>1.0</version>
        <scope>runtime</scope>
    </dependency>
</dependencies>

Now when the mylib module is referenced by other modules (as a dependency) the thirdparty modules will also be downloaded as transitive dependencies.

mliebelt

The base idea is the following:

  • Maven is good in handling with one result per Maven POM.
  • It is possible to have libraries and dependencies to these libraries in your local repositories only.

So you have to do the following steps:

  1. Define for the additional library a separate project (or a module in your project) and define the library as the result.
  2. Change your POM so that this POM has now a dependency to the new project.
  3. Do the same steps for your DLL (see the post Managing DLL dependencies with Maven) how to do that).
  4. Deploy your additional library and your DLL to your local repository.

Now you should be able to use Maven for the build process again, and by using additional plugins like the maven-assembly-plugin, you are able to pack all together.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!