In Unix I can do the following to delete a file from my jar
zip -d myfile.jar META-INF/SIGN.RSA
Is there a simple way to do it in Gradle/Groovy?
I don't want to unzip and re-zip the whole file as I have some very large jars.
As you can probably tell I am un-signing some jars before re-signing them with my own. If you have a solution for that (and doesn't require unpacking and repacking) I'll accept your answer too.
Per my knowledge there's no built-in task for this specific case.
However, you can easily do it by using exec, e.g.:
exec {
executable "jar.exe"
args "-d", "myfile.jar", "META-INF/SIGN.RSA"
}
Related
I've created a release on Azuredevops with a Command Line Task.
The script is really simple :
Unzip the artifcats and move it to another folder.
But owner's folder is not the same between the Agent Deployment and the repository.
I add chmod 777, it's works, but is not the best answer.
Do you have another solution ?
AzureDevops Release - Command Shell “do not have permissions”
Indeed, to unzip the artifcats and move it to another folder, we could use Extract Files task to complete this:
Extract Files task
Use this task in a build or release pipeline to extract files from
archives to a target folder using match patterns. A range of standard
archive formats is supported, including .zip, .jar, .war, .ear, .tar,
.7z, and more.
BTW, there is an extension to Unzip a directories Zip and unzip directory build task
Hope this helps.
I have some .tar.gz-Archives and would like to only unpack the Tarball to create a sha256-checksum hash of the .tar-File. (The reason for this is that the archive will be un- and repacked later on, as we are generating patch-files.)
Now this seems like an easy task but I'm stuck. There are either Gradle examples for:
getting the unpacked tarTree (with a Gradle Copy-Task and tarTree(resources.gzip('model.tar.gz')) (from documentation: working with files)
unzipping Files (with zipTree), which does not work with gzipped files
Both approaches do not work, since I need to create a checksum of the .tar-File itself. Unfortunately I can't use commandLine or gunzip as the tasks should run on both Windows and Linux.
The only solution I can imagine of right now is unpacking the tar.gz to a fileTree and repacking it to a tar-file, but I'm not even sure the checksum would be the same.
Is there really no way to do this directly?
Finally I got it to work with help from a colleague.
Using resources.gzip(), which returns a ReadableResource, we can copy the resulting InputStream into a .tar-file with IOUtils.copy:
file("test.tar").withOutputStream { outputFile ->
IOUtils.copy(resources.gzip(file("test.tgz")).read(), outputFile)
}
We also needed to add Apache commons ("commons-io:commons-io:2.6") as a dependency.
I need to execute groovy script with gradle, but the thing is that these scripts are located in external directory (let's say it's Desktop). I've heard, that in previous versions of Gradle (currently working on 3.2.1) it was not possible, since it is not part of the gradle project. I wonder if it is possible now, or do I have to copy all these scripts into some folder located in gradle project, to execute it.
User story:
I found script in external directory (based on some properties passed to console) - I have absolute path to the script
Now I want to execute this script (build.gradle) without copying it into my gradle project
I'm pretty green with gradle and I hope I made my point clear.
Thanks for help and every attempt :)
Is that what you're looking for? To run the script clone the repository, navigate to 42556631/project folder and run the command:
gradle -b ../script/build.gradle clean build
yes you need to move build.gradle file into project/Build Script folder and then run it.
How do I add .java files to my jar?
My classes, in the bin/ folder, are like:
aaa/b/c/program.class and /aaa/b/c/d.class
So I add a/ to the jar and set the entry point to aaa.b.c.Program.
Then I can: java -jar foo.jar
and the program runs.
If I jar up the src/aaa/* and bin/aaa/* files, it isn't able to find aaa/b/c/Program.class - I tried several ways of specifying the entry point. It seem that the path must match the package+class name.
What's the proper way to make the jar file?
It won't let me add the java and class paths to the same folders easily.
If I go to the parent folder and add the files:
jar -cef x.jar aaa.b.c.Program -C src aaa -C bin aaa
I get : : : java.util.zip.ZipException: duplicate entry: aaa/
To get them in the same folders, I can do it in two steps:
jar -cef x.jar aaa.b.c.program -C bin aaa
jar -uf x.jar -C src aaa
Is this the proper way?
If there are docs, do I put them in the same folders, too?
I searched a bunch on the web and am not finding this,
even (especially?) in the lame Oracle docs...
(I tried to get Eclipse to do it- but it won't let me leave some classes out... But I really want to do this with the command line...)
Thanks
If you want to have the compiled classes and the sources in the same folders, then you have to use two steps, a jar cf step to create the file with one set of files, and a jar uf step to add the other set of files, as in your example.
But doing this is not recommended. The recommended practice is to separate the runnable, the sources and the docs, and use a dedicated jar file for each. As you're doing something unusual, it's no surprise that there's no easy way to do it (you need two steps).
Right now my situation is like this. I created a war file using eclipse in window. Now i want to zip my war file together with my bash script so that automate installation will occur. Is it anyway so that my bash script can automatically recognize my war file?
You could easily use the zip command. See man zip for more details.
If you want to archive multiples war files in the same directory :
lstPath=""
for warFile in "$DIR"/*.zip; do
lstPath="$lstPath $warFile"
done
zip a.zip lstPath
Or :
lstPath=""
for warFile in "$DIR"/*.zip; do
zip a.zip "$warFile"
done
And if the war files are not in the same directory, you could use the find command ;)