task fullZip(type: Zip) {
baseName = 'fullZip'
from projectDir.parentFile
exclude 'build'
}
Looking to zip complete project, with the entire subprojects/modules.
Gradle task never completes and the size of the zip is building up to enormous size while it's a small project in general.
This zip task is part of gradle file in one of the module.
From the half cooked zip file, I can see build directories, which should have been excluded are present.
You need to use exclude **/build/*.
Related
I have my archive at location myProject/unzip and need to:
Zip the contents within the unzip folder and create a zip file with some name at any location within the project.
Using gradle 2.3.
Can anyone help me for this?
I am not sure what you are doing differently than the examples in the documentation from the link I gave in the comments. But this works for me with Gradle 2.3:
task myZip(type: Zip){
from "$projectDir/unzip"
archiveName = "my-zip.zip"
destinationDir = buildDir
}
The input folder is called unzip and needs to present as a child in the project folder. It outputs a file my-zip.zip in the build folder.
Be sure that there actually are some resources located in the from path, or Gradle might skip it.
I new to Gradle. I'm trying to have all dependencies from my project copied to folder build/lib. Is it possible to do that?
Currently, I have a .zip and a .tar in build/distributions via the distribution plugin. However, I would like to have just the uncompressed libs.
I've seem a possible solution here, however I would like to have this as part of the main build and not as a separated task.
Just add the task as a dependency to build. That way it will be "part of the main build".
task copyDependencies(type: Copy) {
from configurations.runtimeClasspath // And/or:
from configurations.compileClasspath
into "$buildDir/lib"
}
build.dependsOn copyDependencies
You can, of cause, also hook it up to any other task that you use to build or deploy the application.
Just in case you are not aware of it, you can also use the installDist task from the distribution plugin (in combination with the application plugin) to create an exploded version in $buildDir/install.
During my gradle build, I generate a temporary buildinfo.properties file containing things like Git commit info, build time, etc. I would like to include this file in my output *.jar / *.war files as a resource. However, I do not want to put this file in my project src/ folder (this would require fiddling with .gitignore and in general it just seems unnecessary to me). Ideally, the developer shouldn't even see this file at all, it should just be contained in the output archive.
How would you include a dynamically generated text file in a Gradle build?
Add that file in a jar task (Kotin DSL):
tasks {
val jar by getting(Jar::class) {
from("build/buildinfo.properties")
}
}
It will add build/buildinfo.properties file (assuming you generate it there with another taks) to the root of your JAR.
For dynamically generated file, standard gradle way to process resources is the gradle task called processResources. You can do something like this:
processResources {
dependsOn taskThatGeneratesYourBuildinfo
from("build/buildinfo.properties") {
into("desired/path/in/jar")
}
}
I am working in an old project which was using Gradle Wrapper v3.2.1, but I want to update it to the latest version (currently v5.4.1).
I have tried updating it to v4.10.2 first but it fails too, so I guess it is something that was not backwards compatible between v3->v4.
The code we have in our build.gradle is:
task buildZip(type: Zip) {
group 'Build'
description 'Assembles a zip archive containing the main classes.'
baseName = "someName"
from compileJava
from processResources
into('lib') {
from configurations.runtime
}
}
Using gradle v3 it included all the libraries (as .jar files) in the .zip file under "lib/" folder, but if I use v4 or later, it does not fail, but it does not include the libraries neither. I have achieved to get the .class files of the dependencies, but that does not work for what I need (AWS Lambda function).
Any idea on how to get the .jar dependencies into the .zip file?
Cheers!
Francisco Robles Martin
So, thanks to Opal comment, I kept looking for a bit more and got a solution, but it seems to not be very correct as I am forcing implementation to allow be resolved:
configurations.implementation.setCanBeResolved(true)
task buildZip(type: Zip) {
group 'Build'
description 'Assembles a zip archive containing the main classes.'
baseName = "someName"
from compileJava
from processResources
into('lib') {
from configurations.implementation
}
}
It works, but I guess there should be a better way to do it without the first line.
I have a gradle project which at main is using java plugin. At subproj1 - thru subproj4 the build.gradle files are also using application plugin. It works well in sub projects to compile the jars (with a main class) and create a distribution zipfile (using resources and dist files).
Now I want to build a 'main' dist zip file, comprising of the contents of all those subproj contents. I found I can run installDist to unzip to each of the subprojects build/install/subprojN
Now at a loss howto in the main only, have a task and/or dependency to create a "main" dist zip file containing: subproj1/** subproj2/** subproj3/** subproj4/**
My thoughts are to do a copy from('.').include('subproj*/build/install//')
then zip that up. but havent figured out howto add the task only at main level, plus have it not complain: NO SOURCE
thanks in advance
Here's an example that just uses two sub-projects, and does not show the compilation of the main code. That stuff should be easy to add. The key to the solution is the zip and zipfileset via the AntBuilder.
Consider this in the main build.gradle:
task uberBuild(dependsOn: ['subProj1:build',
'subProj2:build']) {
doLast {
ant.mkdir(dir: "${projectDir}/dist")
def PATH = "build/distributions"
ant.zip(destfile: "${projectDir}/dist/uber.zip") {
zipfileset(src: "${projectDir}/subProj1/${PATH}/subProj1.zip")
zipfileset(src: "${projectDir}/subProj2/${PATH}/subProj2.zip")
}
}
}
This will write ~/dist/uber.zip, which has the contents:
$ jar tf dist/uber.zip
subProj1/
subProj1/bin/
subProj1/lib/
subProj1/bin/subProj1
subProj1/bin/subProj1.bat
subProj1/lib/subProj1.jar
subProj2/
subProj2/bin/
subProj2/lib/
subProj2/bin/subProj2
subProj2/bin/subProj2.bat
subProj2/lib/subProj2.jar