IllegalArgumentException in maven-resources-plugin during deploy goal

Tags: , , ,



I am trying to build my spring-boot application using maven using below command.

mvn -X -Dmaven.test.skip=true deploy

During this step, maven-resources-plugin tries to copy my application.yaml file to my targetclasses folder. And this fails with an IllegalArgumentException.

Relevant part of the stack trace.

[INFO] Copying 1 resource
[DEBUG] Copying file application.yaml
[DEBUG] file application.yaml has a filtered file extension
[DEBUG] Using 'UTF-8' encoding to copy filtered resource 'application.yaml'.
[DEBUG] filtering XXXsrcmainresourcesapplication.yaml to XXXtargetclassesapplication.yaml
Caused by: java.lang.IllegalArgumentException
    at java.nio.Buffer.position (Buffer.java:244)
    at org.apache.maven.shared.utils.io.FileUtils.copyFile (FileUtils.java:1946)
    at org.apache.maven.shared.filtering.DefaultMavenFileFilter.copyFile (DefaultMavenFileFilter.java:98)
    at org.apache.maven.shared.filtering.DefaultMavenResourcesFiltering.filterResources (DefaultMavenResourcesFiltering.java:262)
    at org.apache.maven.plugins.resources.ResourcesMojo.execute (ResourcesMojo.java:356)

Any ideas on why this is failing? How can I ensure that my file gets copied?

My build succeeds if I delete my yaml file from resources folder!

More stacktrace

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources) on project sonar-notification-app: Execution default-resources of goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources failed.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-resources of goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources failed.
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:148)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
Caused by: java.lang.IllegalArgumentException
    at java.nio.Buffer.position (Buffer.java:244)
    at org.apache.maven.shared.utils.io.FileUtils.copyFile (FileUtils.java:1946)
    at org.apache.maven.shared.filtering.DefaultMavenFileFilter.copyFile (DefaultMavenFileFilter.java:98)
    at org.apache.maven.shared.filtering.DefaultMavenResourcesFiltering.filterResources (DefaultMavenResourcesFiltering.java:262)
    at org.apache.maven.plugins.resources.ResourcesMojo.execute (ResourcesMojo.java:356)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)```

Answer

Finally found the issue with this. When we were packaging the application, we were using the maven-dependency-plugin to copy two artifact classes to a single classes folder. And both the artifacts had their own application.yaml file. This was causing this error. Hope this helps for anyone who encounters something similar.



Source: stackoverflow