How to make deployment of PHP files with Gradle - 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.

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
...

Customize working directory run gradle run task / project structure for web application

I'm working on small web app and I want to serve static files. I'm using application plugin. Part of it is distribution plugin which copies src/main/dist files into distribution zip. Running application with gradlew run uses project dir as working directory. For this reason static files are not found.
Is there a simple way to change working directory for run task?
Is there any other recommended structure for web app gradle project setup?
I have had a similar case when running './gradlew run' of a Kotlin (console) app. The default working directory is the application directory, but IntelliJ uses the root project directory by default.
I have managed to change the working directory by setting the workingDir property of the run task. The list of properties can be found on https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Exec.html
application {
mainClass.set("myproject.HelloKt")
// Change the working directory for the run task. Here is an example:
tasks.run.get().workingDir = rootProject.projectDir
}
You need to add the following to your build.gradle file to modify the working directory of a gradle task.
File runningDir = new File('build/run/')
runningDir.mkdirs()
tasks.run.workingDir = runningDir
Check this thread for reference.

Gradle files not recognised in new directory structure?

Previously we made a Gradle project in Intellij and all the gradle files were there under the project. However, we have now moved the files in this project to a sub folder, but the Gradle files aren't being recognised. The picture below is the new folder set up where our code from the original project is now in the server folder (where the Gradle files are). When I mark the src folder (under server) as the Sources Root, that is when the dependencies from Gradle aren't recognised.
I figured out that the correct way to go is actually to separate out the client/server folder into two separate modules.

Moving gradle build to another machine

It seems that when Gradle 3.1 downloads the dependencies for your project it stores them in:
C:\Users\username\.gradle\caches
I tried copying the contents of this folder to a different machine that has a fresh Gradle 3.1 installation, but when I try to build my project it still tries to download all of the dependencies from scratch, which then fails because the new machine has no internet connection.
How do I get around this?
Compress main folder C:\Users\username.gradle to gradleHome.zip
Copy and uncompress this gradleHome.zip file to another folder for example D:\gradle_home
set gradle_home environment variable to this new folder. See how to change environment variables in windows here.enter link description here

How do I do post-compile bundling in Maven?

I have a maven project that contains some Kotlin source files and some web resources (HTML/CSS). During the compile phase, the Kotlin source is compiled to JavaScript and ends up in the build output location, along with some other folders that I am not familiar with.
I would like a build step that occurs after the compile is finished that will copy my resources and compiled output and dependencies (kotlin.js) into a folder with the correct hierarchy that I deploy or debug.
I know how to copy the resources into the build output folder, but the build output folder appears to have some other files in it that are auto-generated by maven which I do not want to deploy.
Ideally, I would also like the clean phase to delete this destination directory.

Resources