javamavenlwjgl

How do I copy dependencies to output directory with `maven package`


I have a project which uses LWJGL, and I would like to copy the required jars and related natives to the output directory of the generated jar. I would not like to inject the dependencies into the final jar itself.

I can run mvn package and mvn dependency:copy-dependencies, both of which work great.

My attempts to run the goal "copy-dependencies" is by adding an execution to the "maven-dependency-plugin" as follows:

<executions>
  <execution>
    <id>copy-dependencies</id>
    <phase>prepare-package</phase>
    <goals>
      <goal>copy-dependencies</goal>
    </goals>
    <configuration>
      <outputDirectory>
        ${project.build.directory}/libs
      </outputDirectory>
    </configuration>
  </execution>
</executions>

and again, as referenced by this answer, with the same result: packaging completes, creating a jar, but no dependencies beside it. no logging that prepare-package is occurring, or the maven-dependency-plugin is being run at all.

I've also tried binding to other phases, such as package, validate, test, and none of them will cause an execution to occur. This is the only execution in my pom.xml. I have only a handful of plugins:

maven-clean-plugin
maven-resources-plugin
maven-compiler-plugin
maven-jar-plugin (with a config declaring its manifest, shown below)
maven-install-plugin
maven-dependency-plugin

Aforementioned config:

<configuration>
  <archive>
    <manifest>
      <addClasspath>true</addClasspath>
      <classpathPrefix>libs/</classpathPrefix>
      <mainClass>
        xyz.valnet.hadean.HadeanGame
      </mainClass>
    </manifest>
  </archive>
</configuration>

I additionally have 3 profiles, for selecting which LWJGL natives to use by setting the property lwjgl-natives and that being used in the dependencies.

My question is mainly: what things could cause this execution to not occur.


Solution

  • plugins listed under <pluginManagement> will only get executed by projects in child directories which have their own pom.xml

    plugins for execution in the current project should be listed without <pluginManagement>

    to fix remove pluginManagement, or re-organize your plugins to correctly reflect which plugins should be run and which should be used for child projects.

    <build>
      <plugins>
        [...]
      </plugins>
      <pluginManagement>
        <plugins>
          [...]
        </plugins>
      </pluginManagement>
    </build>