Howto untar tar.gz file containing Oracle JDK

I am trying to package an Oracle JDK distribution into an RPM. To do this I must untar the tar.gz file. According to User Guide, I could try doing it like this:

        project.tasks.create("rpm", Rpm) { 
            project.afterEvaluate {
         ...
                into(destPath) {
                    from project.tarTree(inputJdkFile)
                }
             }
         }

But when I do that, I get the error message

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':jdk32:rpm'.
> Unable to expand TAR '/vtone/3rd-party/JDKS/jdk-8u101-linux-i586.tar.gz'
    The tar might be corrupted or it is compressed in an unexpected way.
    By default the tar tree tries to guess the compression based on the file extension.
    If you need to specify the compression explicitly please refer to the DSL reference.

Consulting the DSL reference I try

    project.tasks.create("rpm", Rpm) { 
        project.afterEvaluate {
        ...
            into(destPath) {
                from project.tarTree(project.resources.gzip(inputJdkFile))
            }
         }
     }

but I get the same error.

Yet the linux tar command has no trouble with this file. And I can hardly believe I need to specify the project.resources.gzip for such a common filetype and such a common file.

The stack trace offers some clues but I don’t know what they mean:

Caused by: org.gradle.api.GradleException: Could not copy tar entry /vtone/3rd-party/JDKS/jdk-8u101-linux-i586.tar.gz!jdk1.8.0_101/THIRDPARTYLICENSEREADME.txt to '/home/sc1478/jdkinstaller/jdk32/build/tmp/expandedArchives/jdk-8u101-linux-i586.tar.gz_e4j07uh9x00wimibzfsxdt3fj/jdk1.8.0_101/THIRDPARTYLICENSEREADME.txt'.
        at org.gradle.api.internal.file.AbstractFileTreeElement.copyTo(AbstractFileTreeElement.java:79)
        at org.gradle.api.internal.file.archive.TarFileTree$DetailsImpl.getFile(TarFileTree.java:139)
        at org.gradle.api.internal.file.copy.DefaultFileCopyDetails.getFile(DefaultFileCopyDetails.java:64)
        at com.netflix.gradle.plugins.packaging.AbstractPackagingCopyAction.extractFile(AbstractPackagingCopyAction.groovy:200)
        at com.netflix.gradle.plugins.rpm.RpmCopyAction.visitFile(RpmCopyAction.groovy:104)
        at com.netflix.gradle.plugins.packaging.AbstractPackagingCopyAction.this$dist$invoke$1(AbstractPackagingCopyAction.groovy)
        at com.netflix.gradle.plugins.packaging.AbstractPackagingCopyAction$StreamAction.methodMissing(AbstractPackagingCopyAction.groovy)
        at com.netflix.gradle.plugins.packaging.AbstractPackagingCopyAction$StreamAction.processFile(AbstractPackagingCopyAction.groovy:60)
        at org.gradle.api.internal.file.copy.NormalizingCopyActionDecorator$1$1.processFile(NormalizingCopyActionDecorator.java:66)
        at org.gradle.api.internal.file.copy.DuplicateHandlingCopyActionDecorator$1$1.processFile(DuplicateHandlingCopyActionDecorator.java:60)
        at org.gradle.api.internal.file.copy.CopyFileVisitorImpl.processFile(CopyFileVisitorImpl.java:60)
        at org.gradle.api.internal.file.copy.CopyFileVisitorImpl.visitFile(CopyFileVisitorImpl.java:44)
        at org.gradle.api.internal.file.AbstractFileTree$FilteredFileTreeImpl$1.visitFile(AbstractFileTree.java:150)
        at org.gradle.api.internal.file.archive.TarFileTree.visitImpl(TarFileTree.java:99)
        at org.gradle.api.internal.file.archive.TarFileTree.visit(TarFileTree.java:78)
        ... 97 more
Caused by: java.io.FileNotFoundException: /home/sc1478/jdkinstaller/jdk32/build/tmp/expandedArchives/jdk-8u101-linux-i586.tar.gz_e4j07uh9x00wimibzfsxdt3fj/jdk1.8.0_101/THIRDPARTYLICENSEREADME.txt (Permission denied)
        at org.gradle.api.internal.file.AbstractFileTreeElement.copyFile(AbstractFileTreeElement.java:91)
        at org.gradle.api.internal.file.AbstractFileTreeElement.copyTo(AbstractFileTreeElement.java:74)
        ... 111 more

Permission errors? Must I explicitly unzip the file first to a temporary directory, then add it to my rpm? But it looks from the stack trace that that is exactly what it is doing and failing.

Problem solved, I think. This won’t work a second time unless you run clean over it first. Once the files are there, you get an error. But, should it work that way?

Nope, this is a live issue again: Even with cleaning, I get the following:

Caused by: java.io.FileNotFoundException: /home/sc1478/jdkinstaller/jdk64/build/tmp/expandedArchives/jdk-8u77-linux-x64.tar.gz_dchh48kmdaayjacylazx24ysr/jdk1.8.0_77/LICENSE (Permission denied)
        at org.gradle.api.internal.file.AbstractFileTreeElement.copyFile(AbstractFileTreeElement.java:91)
        at org.gradle.api.internal.file.AbstractFileTreeElement.copyTo(AbstractFileTreeElement.java:74)
        ... 111 more


BUILD FAILED

Total time: 4.037 secs

and yet:

$ ls -al /home/sc1478/jdkinstaller/jdk64/build/tmp/expandedArchives/jdk-8u77-linux-x64.tar.gz_dchh48kmdaayjacylazx24ysr/jdk1.8.0_77/LICENSE
-r–r–r-- 1 sc1478 dev 40 Aug 26 12:42 /home/sc1478/jdkinstaller/jdk64/build/tmp/expandedArchives/jdk-8u77-linux-x64.tar.gz_dchh48kmdaayjacylazx24ysr/jdk1.8.0_77/LICENSE

Is this some sort of timing issue? I can see no reason for the permission denied error.

Someone should have a look at this. It might be the nebula rpm plugin or gradle itself, but I was unable to get beyond it except via the workaround of using an Exec task to run the tar command into a temporary directory, then pull from that into the rpm.

1 Like

Hi Steve, thanks for reporting the problem.

These issues in Jira might be related:
https://issues.gradle.org/browse/GRADLE-3269
https://issues.gradle.org/browse/GRADLE-3310
https://issues.gradle.org/browse/GRADLE-2959 (fixed in 2.9)

What Gradle version are you using?

Regards,

Lari

This was with gradle 3.0. The files where the errors happen appear to be read-only (444 permission), although as indicated above, it does not appear to matter if clean is run first.