"can't write to read-only destination file" with ANT

Viewed 2781

Ant build fails with below error about "can't write to read-only destination file". Is this an issue with Windows permissions error or something with Ant?

BUILD FAILED
E:\app\jenkins\workspace\CardsAdmin\Test-Build2\ca_module\build.xml:32: The following error occurred while executing this line:
E:\app\jenkins\workspace\CardsAdmin\Test-Build2\ca_module\caRest\build.xml:116: Failed to copy E:\app\jenkins\workspace\CardsAdmin\Test-Build2\ca_module\caRest\WebContent\WEB-INF\tealeaf-w3c-dev.js to E:\app\jenkins\workspace\CardsAdmin\Test-Build2\ca_module\caRest\WebContent\WEB-INF\web\tealeaf-w3c-dev.js due to can't write to read-only destination file E:\app\jenkins\workspace\CardsAdmin\Test-Build2\ca_module\caRest\WebContent\WEB-INF\web\tealeaf-w3c-dev.js
2 Answers

In my case i had the problem with this configuration in my pom.xml, which throws that exception (can't write to read-only destination file) when i run mvn -Dmaven.test.skip=true clean package:


<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
      <execution>
        <goals>
          <goal>run</goal>
        </goals>
        <phase>generate-sources</phase>
        <configuration>
          <target>
            <echo force="true" file="${basedir}/src/main/resources/version.properties" message="test.version=${project.version}${line.separator}"/>
            <echo force="true" file="${basedir}/src/main/resources/version.properties" message="test.build=${buildNumber}${line.separator}" append="true"/>
            <echo force="true" file="${basedir}/src/main/resources/version.properties" message="test.timestamp=${timestamp}" append="true"/>
          </target>
        </configuration>
      </execution>
    </executions>
</plugin>

The key was to put force="true" in each "echo" tag.

Related