Maven-publish plugin does not release file locks after publishing

After publishing artifacts with maven-publish using http or https protovol all transfered files remain open by the process. If it runs as a gradle daemon under windows OS the files can not be deleted unless the daemon is stopped.

To reproduce the problem consider the following gradle script:

plugins.apply 'maven-publish'
group = 'my.gradle.test.group'
version = "0.0_SNAPSHOT"
def file = file("${project.buildDir}/publishedFile.txt")
file.parentFile.mkdirs()
file.write 'content'
publishing {
  publications {
    mavenCustom(MavenPublication) { MavenPublication publication ->
      publication.artifactId = 'artifact'
      publication.artifact file.absolutePath
    }
  }
}
publishing {
  repositories {
    maven {
      url 'http://build1.intern/nexus/content/repositories/snapshots/'
      credentials {
        username System.getenv('NEXUS_USER')
        password System.getenv('NEXUS_PASS')
      }
    }
  }
}
task 'publishAndCleanUp'
publishAndCleanUp.doLast {
  file.delete()
  if(file.exists())
    throw new GradleException ("${file.path} exists after deletion")
}
publishAndCleanUp.dependsOn publish

Running task publishAndCleanUp under Windows cause the exception to be thrown because the file is still open when file.delete() is called. Not only the artifact file but also other files transfered to server like maven-metadata-remote.xml remain blocked after publish is executed

The problem is caused by method

 org.gradle.internal.resource.transport.http.RepeatableInputStreamEntity.writeTo

which opens file streams and never closes them.

Thanks for the report, Dimitry. I’ve confirmed this to be an issue and am working on a fix.
I’ll update GRADLE-3333 when it’s fixed.

Fixed in master: this fix will be in Gradle 2.7.
If you can confirm with a nightly build that would be great. (You’ll need 20150815 or later).

Thanks again for the report.

Thanks a lot for the immediate fix. I am on holidays now, so I shall verify the fix next weekend.

Best regards,
Dimitry

My test with nightly build gradle-2.7-20150817015842 was succesful, I can confirm that the bug seems to be fixed.