Copy jar file to multiple location with gradle - gradle

I'm working with a Spring Boot App, and I want to copy the jar files as a dependency to libs folder of multiple projects. I have all the below projects in the same dir and the jar file is located in common project, the jar file is located in common/build/libs/*.jar:
reward
product
membership
client
common (jar's file location)
I am able to copy it to a single location at a times with this below snipped script:
task deploy (type: Copy) {
from "build/libs/le-common-1.0.0-SNAPSHOT-plain.jar"
into "${project.rootProject}/../../le-reward/libs"
Any help would be really appreciated, thanks in advance.

Related

Jenkins Job - Creating a zip file with war file, appspec.yml and scripts folder

I have created a build with Jenkins for a spring boot application and it is creating a war file.
Now I want to create a second job which should create a zip file with the war file created and appsepc.yml file and a folder "scripts" folder which contains some shell script that the appspec.yml file uses. Can anyone let me know how to do this?
The job name is "Package" so the following is the structure where the different files are.
.jenkins\workspace\Package\target\cpproject.war
.jenkins\workspace\Package\appspec.yml
.jenkins\workspace\Package\scripts\after_install.sh
.jenkins\workspace\Package\scripts\before_install.sh
.jenkins\workspace\Package\scripts\start_server.sh
.jenkins\workspace\Package\scripts\stop_server.sh
Thank you.
See the Maven Assembly Plugin:
The Assembly Plugin for Maven enables developers to combine project output into a single distributable archive that also contains dependencies, modules, site documentation, and other files.
Currently it can create distributions in the following formats:
zip
...

What does Gradle do with the files, which are located in src/main/resources directory?

I'm trying to figure out, what Gradle does with the files, which are located in src/main/resources directory.
The processResources task, added by the java plugin to the project, copies them to the build/resources/main directory.
The content of this directory is bundled into the jar file created by the jar task that is also added by the java plugin, and the resources can thus be loaded, at runtime, by the ClassLoader.
See the documentation of the java plugin.
it might do nothing with them, but ignore them - per default (with the Android plugin) that directory is called res, only the Java plugin would take the resources directory into account (the question does not indicate which plugin is used). otherwise it would run a processResources task on them; only res/raw is not being processed (copied 1:1).

How to make deployment of PHP files with Gradle

I have Android Studio project, where I store (in separate folder) PHP files (implementing web services). The whole project is built and maintained by Gradle plugin to Studio.
How to make Gradle to deploy (copy) these files from project to external Apache \htdocs localisation? Is it possible to copy theses files during Gradle build process? if so, how to copy them only if there are differences between files in project folder and files in external \htdocs localisation.
I will appreciate any help.
Assuming your Apache server runs on the same machine, you can create a Gradle copy task to copy single files or whole directories to a specific location:
task copyWebFiles(type: Copy) {
from 'src/web' // source directory
into '../path/to/htdocs' // target directory
}
preBuild.dependsOn copyWebFiles // execute task before build
As part of your app's build.gradle file.

Delete/Remove file from war with Gradle

I'm using gradle to build a Spring Boot application, and I would like to have the application.properties file removed from the war, because that will be loaded externally (this is running in a tomcat container, not embedded).
I've looked around StackOverflow and the Gradle docs to try to figure out what to do, but I don't know which phase to tie into, and if I exclude the file before or after the war is created. There also seem to be multiple ways of dealing with files.
I believe Maven uses packagingExcludes for the equivalent.
Although I was not able to prevent a file from being added to the war, I was able to remove a file after the war was created - thanks in part to a tip from this question: Is there a quick way to delete a file from a Jar / war without having to extract the jar and recreate it?
In my build.gradle file I appended the war command with an exec command so that I could run a command after the war file had been created. The command will remove the application.properties file from the war. This is what the task extension looks like:
war << {
exec {
workingDir 'build/libs'
commandLine 'zip', '-d', "${appName}-${appVersion}.war", 'WEB-INF/classes/application.properties'
}
}
In short, it changes the working directory to the location that gradle places the war, and then uses the zip command to remove a file from the war.
You also have the option that if you don’t care for these properties files to be copied from the src/main/resources to the build/resources/main folder (not just excluded when build/resources/main is copied to the War), you could use:
In build.gradle file;
processResources {
exclude('application.properties')
}

CMYKJPEGImageReaderSpi not loading

I was having an issue of reading CMYK JPEG images , and have used below url as reference for solving the issue.
http://www.randelshofer.ch/blog/2011/08/reading-cmyk-jpeg-images-with-java-imageio/
I have given the configuration org.monte.media.jpeg.CMYKJPEGImageReaderSpi in the file javax.imageio.spi.ImageReaderSpi under path /META-INF/services/javax.imageio.spi.ImageReaderSpi.
This works perfectly inside eclipse and the image reader is loaded successfully.
This file is not loading when deployed , i can find the folder and the file in the generated war file in my desired jar file inside lib folder, i guess i need to add it to java classpath.
Please help me to add to classpath or if there is any other issue with it.
You need to add this file as a static resource to your build lifecycle.
For Ant or Gradle you just need to write a simple copy task (Ant task, Gradle task), for Maven you can use Maven Resources Plugin.
After that your file should appears in your app package.

Resources