57

I am building my project using Maven. My maven version is apache-maven-3.0.4. I am using Eclipse Luna. When I try to build my project I get the following error

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.7:resources (default-resources) on project OrionCommunity: Mark invalid -> [Help 1].

Following is the stack trace when I run mvn clean install -X:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:53.295s
[INFO] Finished at: Thu Oct 09 20:00:26 IST 2014
[INFO] Final Memory: 9M/25M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.7:resources (default-resources) on project OrionCommunity: Mark invalid -> [Hel
p 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.7:resources (default-resources)
 on project OrionCommunity: Mark invalid
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: Mark invalid
        at org.apache.maven.plugin.resources.ResourcesMojo.execute(ResourcesMojo.java:306)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
        ... 19 more
Caused by: org.apache.maven.shared.filtering.MavenFilteringException: Mark invalid
        at org.apache.maven.shared.filtering.DefaultMavenFileFilter.copyFile(DefaultMavenFileFilter.java:129)
        at org.apache.maven.shared.filtering.DefaultMavenResourcesFiltering.filterResources(DefaultMavenResourcesFiltering.java:264)
        at org.apache.maven.plugin.resources.ResourcesMojo.execute(ResourcesMojo.java:300)
        ... 21 more
Caused by: java.io.IOException: Mark invalid
        at java.io.BufferedReader.reset(BufferedReader.java:485)
        at org.apache.maven.shared.filtering.MultiDelimiterInterpolatorFilterReaderLineEnding.read(MultiDelimiterInterpolatorFilterReaderLineEnding.java:416)
        at org.apache.maven.shared.filtering.MultiDelimiterInterpolatorFilterReaderLineEnding.read(MultiDelimiterInterpolatorFilterReaderLineEnding.java:205)
        at java.io.Reader.read(Reader.java:123)
        at org.apache.maven.shared.utils.io.IOUtil.copy(IOUtil.java:181)
        at org.apache.maven.shared.utils.io.IOUtil.copy(IOUtil.java:168)
        at org.apache.maven.shared.utils.io.FileUtils.copyFile(FileUtils.java:1856)
        at org.apache.maven.shared.utils.io.FileUtils.copyFile(FileUtils.java:1804)
        at org.apache.maven.shared.filtering.DefaultMavenFileFilter.copyFile(DefaultMavenFileFilter.java:114)
        ... 23 more

My maven repository is under D:/mavenrepo. I have completely deleted all the jars present in the repo and did a clean install. But I still get this error.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Avinash Reddy
  • 2,204
  • 3
  • 25
  • 44
  • no pom.xml, no logs (except the tail). it's impossible to help you or reproduce an issue. read here: http://stackoverflow.com/help/how-to-ask – ursa Oct 09 '14 at 15:03
  • 2
    This looks like you are filtering some kind of files which you shouldn't. Make `mvn -X compiler | tee mvn.log` and check the log file for `[DEBUG] filtering`. There you can see which file is being filtered. My assumption is you have missed to add files to the `nonFilteredFileExtension`. – khmarbaise Oct 09 '14 at 15:19
  • @khmarbaise Thank you very much. You were my savior of the day.As suggested by you i ran the command and could see in the log the resources getting filtered. In my pom.xml i had the following piece of code – Avinash Reddy Oct 10 '14 at 10:03
  • src/main/resources true After commenting it the build was successful.The resources which are being filtered are not needed for the build. But not sure why the build does not work with that piece of code – Avinash Reddy Oct 10 '14 at 10:23
  • My colleague got the same issue but the problem was with one of the file. Not sure what the problem is. We removed the file which was causing the problem and had the filtering code as is and ran the build.It was successful. I hope the problem is only with that specific file and that to the file was changed 3 months back and there were no recent code changes in it – Avinash Reddy Oct 10 '14 at 10:47
  • @AvinashReddy You should accept an answer if it worked for you. I had similar issue, and below top ranked answer helped me resolve the issue. – Wand Maker Jun 19 '16 at 15:48

13 Answers13

71

With:

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.7</version>
        </plugin>

Was getting the following exception:

...
Caused by: org.apache.maven.plugin.MojoExecutionException: Mark invalid
    at org.apache.maven.plugin.resources.ResourcesMojo.execute(ResourcesMojo.java:306)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 25 more
Caused by: org.apache.maven.shared.filtering.MavenFilteringException: Mark invalid
    at org.apache.maven.shared.filtering.DefaultMavenFileFilter.copyFile(DefaultMavenFileFilter.java:129)
    at org.apache.maven.shared.filtering.DefaultMavenResourcesFiltering.filterResources(DefaultMavenResourcesFiltering.java:264)
    at org.apache.maven.plugin.resources.ResourcesMojo.execute(ResourcesMojo.java:300)
    ... 27 more
Caused by: java.io.IOException: Mark invalid
    at java.io.BufferedReader.reset(BufferedReader.java:505)
    at org.apache.maven.shared.filtering.MultiDelimiterInterpolatorFilterReaderLineEnding.read(MultiDelimiterInterpolatorFilterReaderLineEnding.java:416)
    at org.apache.maven.shared.filtering.MultiDelimiterInterpolatorFilterReaderLineEnding.read(MultiDelimiterInterpolatorFilterReaderLineEnding.java:205)
    at java.io.Reader.read(Reader.java:140)
    at org.apache.maven.shared.utils.io.IOUtil.copy(IOUtil.java:181)
    at org.apache.maven.shared.utils.io.IOUtil.copy(IOUtil.java:168)
    at org.apache.maven.shared.utils.io.FileUtils.copyFile(FileUtils.java:1856)
    at org.apache.maven.shared.utils.io.FileUtils.copyFile(FileUtils.java:1804)
    at org.apache.maven.shared.filtering.DefaultMavenFileFilter.copyFile(DefaultMavenFileFilter.java:114)
    ... 29 more



Then it is gone after adding maven-filtering 1.3:

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.7</version>
          <dependencies>
            <dependency>
                <groupId>org.apache.maven.shared</groupId>
                <artifactId>maven-filtering</artifactId>
                <version>1.3</version>
            </dependency>
          </dependencies>
        </plugin>
Krutik Jayswal
  • 3,165
  • 1
  • 15
  • 38
arntg
  • 1,557
  • 14
  • 12
14

remove this work for me:

<filtering>true</filtering>

I guess it is caused by this filtering bug

Justin
  • 1,050
  • 11
  • 26
  • 7
    filtering might be necessary on some project.. this is not a correct answer, in my opinion – antoine Apr 24 '15 at 11:33
  • We had filtering set in our master POM and so couldn't easily remove this. We had moved to 2.7. The better approach was described above: http://stackoverflow.com/a/28864641/1279002 and we added a dependency on maven-filtering 1.3 – theINtoy Apr 19 '16 at 13:42
8

I had this issue too because I was filtering /src/main/resources and forgot I had added a keystore (*.jks) binary to this directory.

Add a "resource" block with exclusions for binary files and your problem may be resolved.

<build>
  <finalName>somename</finalName>
  <testResources>
    <testResource>
      <directory>src/test/resources</directory>
      <filtering>false</filtering>
    </testResource>
  </testResources>
  <resources>
    <resource>
      <directory>src/main/resources</directory>
      <filtering>true</filtering>
      <excludes>
        <exclude>*.jks</exclude>
        <exclude>*.png</exclude>
      </excludes>        
    </resource>
  </resources>
...
Dan
  • 81
  • 1
  • 3
4

What worked for me is to add include tag in order to specify exactly what I want to filter.

It seems the resource plugin has problems going through the whole src/main/resource folder, probably due to some specific files inside.

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>application.yml</include>
            </includes>
        </resource>
    </resources>
sashok_bg
  • 2,436
  • 1
  • 22
  • 33
4

I fixed the same issue by referencing the latest maven resource plugin release:

<dependency>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>3.2.0</version>
</dependency>
Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
3

In my case the targetPath was not having any value it was blank in the resources --> resource for the file directory with files that had issue. I had to update it to global as seen in the Code Sample 2 and re-run build to fix the issue.

Code Sample 1 (with issue)

<build>
    <resources>
        <resource>
            <directory>src/main/locale</directory>
            <filtering>true</filtering>
            <targetPath></targetPath>
            <includes>
                <include>*.xml</include>
                <include>*.config</include>
                <include>*.properties</include>
            </includes>
        </resource>
    </resources>

Code Sample 2 (fix applied)

<build>
    <resources>
        <resource>
            <directory>src/main/locale</directory>
            <filtering>true</filtering>
            <targetPath>global</targetPath>
            <includes>
                <include>*.xml</include>
                <include>*.config</include>
                <include>*.properties</include>
            </includes>
        </resource>
    </resources>

Santosh Sindham
  • 879
  • 8
  • 18
3

From official documentation

Warning: Do not filter files with binary content like images! This will most likely result in corrupt output.

If you have both text files and binary files as resources it is recommended to have two separated folders. One folder src/main/resources (default) for the resources which are not filtered and another folder src/main/resources-filtered for the resources which are filtered.

<project>
  ...
  <build>
    ...
    <resources>
      <resource>
        <directory>src/main/resources-filtered</directory>
        <filtering>true</filtering>
      </resource>
      ...
    </resources>
    ...
  </build>
  ...
</project>

Now you can put those files into src/main/resources which should not filtered and the other files into src/main/resources-filtered.

As already mentioned filtering binary files like images,pdf`s etc. could result in corrupted output. To prevent such problems you can configure file extensions which will not being filtered.

Most certainly, You have in your directory files that cannot be filtered. So you have to specify the extensions that has not be filtered.

Radouane ROUFID
  • 10,595
  • 9
  • 42
  • 80
2

I had the same error because of character '@' in my resources/application.properties. All I did was replacing the '@' for its unicode value: eureka.client.serviceUrl.defaultZone=http://discUser:discPassword\u0040localhost:8082/eureka/ and it worked like charm. I know the '@' is a perfectly valid character in .properties files and the file was in UTF-8 encoding and it makes me question my career till today but it's worth a shot if you delete content of your resource files to see if you can get pass this error.

Georgee
  • 17
  • 2
1

I faced the same problem and did the filtering false like below working for me. You can try the same...

<testResources>
    <testResource>
        <directory>src/test/java</directory>
        <filtering>false</filtering>
    </testResource>
    <testResource>
        <directory>src/test/resources</directory>
        <filtering>false</filtering>
    </testResource>
</testResources>
Vojtech Ruzicka
  • 16,384
  • 15
  • 63
  • 66
  • 2
    As mentioned in previous comment, filtering is sometimes needed in the project, thus not a valid answer imo – sashok_bg Feb 23 '17 at 10:49
1

in my case, it was a confilict with IntelliJ , I've resolved it by building the project from command line and it worked!

1

I solved that by changing coding format of ressources files to UTF-8

0

This could be a issue in mvn home path in IntellijIdea IDE. For me it worked out when I set the mvn home directory correctly.enter image description here

shamila
  • 1,280
  • 6
  • 20
  • 45
0

Thanks for all the suggestions. I'm using temurin-11.jdk & Spring-Boot 2.7.5 I opted to go the plugin upgrade route.

My Original error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.7:resources 
(default-resources) on project my-app: Mark invalid -> [Help 1]

After Upgrading my pom as follows:

I've got this resources bit in my build section:

<resources>
  <resource>
    <directory>src/main/resources</directory>
    <filtering>true</filtering>
  </resource>
</resources>

And then this is my plugin definition:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-resources-plugin</artifactId>
  <version>3.3.0</version>
  <configuration>
    <delimiters>
      <delimiter>@</delimiter>
    </delimiters>
    <useDefaultDelimiters>false</useDefaultDelimiters>
  </configuration>
</plugin>

I got a new error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.3.0:resources 
(default-resources) on project my-app: filtering /Users/me/IntelliJ_Workspace/my-app/my-app/src/main/resources/static/fonts/glyphicons-halflings-regular.woff 
to /Users/me/IntelliJ_Workspace/my-app/my-app/target/classes/static/fonts/glyphicons-halflings-regular.woff 
failed with MalformedInputException: Input length = 1 -> [Help 1]

As you can see a .woff file extension contains at least 1 matching delimiter but fails to parse. In my case I don't want filtering on anything but .properties & .yaml files. After reading the maven-resources-plugin/resources docs I found there's a config nonFilteredFileExtensions where we can exclude file extensions we don't want to filter. So my final plugin config looks like:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-resources-plugin</artifactId>
  <version>3.3.0</version>
  <configuration>
    <delimiters>
      <delimiter>@</delimiter>
    </delimiters>
    <useDefaultDelimiters>false</useDefaultDelimiters>
 <nonFilteredFileExtensions>jpg,jpeg,gif,bmp,png,svg,ttf,woff,woff2</nonFilteredFileExtensions>
  </configuration>
</plugin>
ranma2913
  • 1,058
  • 10
  • 8