How can I package a jar file (packaged via buildr) and script files into a zip file? The jar file is created as per the buildfile:
define "myapp" do
...
package(:jar)
...
end
I tried Zip Task, but it didn't work.
You can use this:
package(:zip).include(package(:jar), :path => "distrib")
Or you can define a subproject for the distrib, see this example.
Related
How can I copy a single file into .jar with a different name using the Gradle task "jar"?
For example
local:src/main/resources/mypkg_prod.properties → jar-file:/mypkg.properties
You can copy the file into the jar and then do a rename.
This is a link to some information on the rename method from the Gradle docs:
https://docs.gradle.org/current/userguide/working_with_files.html#sec:renaming_files
Example:
jar {
from 'my_file.txt'
rename 'my_file.txt', 'my_super_file.txt'
}
Note: If your file is already being included in the jar, just add the rename line to the jar task:
jar {
rename 'mypkg_prod.properties', 'mypkg.properties'
}
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.
By default, Gradle puts all WAR files that it creates in build/libs when I run gradle build on a Java project. How do I instruct Gradle to create a directory called dist under build and put all WAR files in that directory (i.e. build/dist)?
I created a new task called moveWar that accomplished what I wanted:
task moveWar(type: Copy) {
from 'build/libs'
into 'build/dist'
}
Then I used build.finalizedBy moveWar to move the WAR file in libs to dist after the build is finished.
Another approach I found:
war.destinationDir = file "$buildDir/dist"
I am using the ShadowJar Gradle plugin to build a Jar containing all of the source files in the src/main/java directory and other Jar files in a lib directory and it is working fine. What I need is another ShadowJar task, a devShadowJar task, that will instead of pulling in a JSON file in the src/main/resources folder, it will pull in a JSON file in the src/dev/resources folder.
I added this to the build.gradle file to define the dev source set:
sourceSets {
dev
}
But now I am not sure how to create a devShadowJar task to use the dev JSON resource instead of the JSON resource file located in src/main/resources.
try playing around this:
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
task devShadowJar(type: ShadowJar) {
zip64 true
from './build/classes/java/main'
from project.configurations.compile
from './src/dev/resources' // or wherever the resources and up under ./build
}
I have the following structure:
src/main/java/com/company/SomeJavaFile.java
src/main/java/com/company/template_file.ftl
When I create a build using gradle, the *.ftl files dont get included in the war file.
How can I make gradle include them in the war file?
Another solution would be to put your *.ftl files into src/main/resources directory instead.
Ok, found it. You simply add the following line to your build file:
gradle.build file (add the following line):
sourceSets.main.resources.srcDir 'src/main/java'
Got the answer from the following discussion thread:
http://gradle.1045684.n5.nabble.com/Copy-non-java-files-into-the-target-directory-td1432058.html
Why not put them in src/main/webapp where, if you used them, *.jsp files would go?