Gradle files not recognised in new directory structure? - gradle

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.

Related

Maven - Wrong folder structure

I have checked in one of my projects to GIT repo. When i cloned it from GIT, imported the project to eclipse and converted the project to Maven Project, the folder structure of maven seems to be a bit different
This should have been src/main/java, src/test/java, src/test/respurces folder structures and com.vod... as package.
I have tried maven>update project, project>clean, maven>clean, eclipse::clean, eclipse::eclipse. But this project structure does not seem to go off.
Any possible solutions for this please?
After importing the project as eclipse general project, below is the structure.
This is a typical problem due to the lack of Eclipse metadata files in the GIT repository.
How to solve it:
Open the project's contextual menu > Java Build Path > Configure Build Path > Source. Drop off folder src and set as folder sources just these:
src\main\java
src\main\resources
src\test\java
src\test\resources
This will save some metadata to the .classpath file.
Also, you should ensure that this was set as a Maven project: Open the project's contextual menu > Configure. If there is the Convert to Maven command, execute it (if not, it is already a Maven project). This might save some metadata to the .project file.
Then, be sure to check in the Eclipse metadata files (.classpath, .project and .settings folder) to GIT. And, in order for this project can be safely shared to other developers, be sure not to enter absolute paths in the java build path, nor other system-dependant constraints.

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.

How to handle projects at the same level with Gradle?

I have two (Java) projects, a library and an executable which uses the library. The two projects reside in subfolders of the same folder but I don't want to add anything (like settings.gradle) in the root folder (they come from different git repositories, thus, I cannot have the files in the common parent source controlled). Here is my layout:
lib - has some runtime dependencies (from the maven repo)
app - depends on lib and has some (different) runtime dependencies
The goal is to produce a folder (Gradle's build\libs is good enough), containing a jar file and a lib subfolder with all runtime dependencies. What is the best approach with Gradle? Here is the result I am looking for:
app\
build\
libs\
app.jar
lib\ - all dependencies are here
With ant for instance, I bring everything together when building the executable (referencing the lib's source code via ../lib/). That's somewhat ugly, but get's the job done. Ideally, I would think that it's more flexible to have the lib build as a dependency, when building the executable, just adding another jar to the app's lib subfolder.
Thanks in advance
You can put your root build.gradle file and the settings.gradle file in a folder named master next to your lib and app folder:
lib - has some runtime dependencies (from the maven repo)
app - depends on lib and has some (different) runtime dependencies
master - root build.gradle file + settings.gradle file
gradle looks for a master folder when searching for a settings.gradle file

Managing external JARs build paths in git controlled eclipse project created in Ubuntu and cloned in Windows

I am having an eclipse project created on Ubuntu, in which all the JARs that I am using, are located in a folder /home/xyz/AllJARs. Here the /home is the system home folder. The project as well as the AllJARs folder is git version controlled on a central git server.
So, all the paths to these JARs in the project's build path are /home/xyz/AllJARs. When I'm cloning the project repo and the AllJARs repo on a Windows machine, I'm shown errors related to build path since it can't find the path /home/xyz/AllJARs.
How can I manage this situation where I can have external JAR files in build paths which can work on Ubuntu as well as on a Windows machine? Thanks in advance.
You have two easy options:
use relative paths: for example, put the JAR folder in the folder above your project, then you can set the JARs' paths to ../AllJARs/
put JARs into project: you can also just put the JARs into the project folder; if you've set them up as "External JARs" in project settings, you'll have to remove them from that list, and re-add them with "Add JARs". Eclipse will then look for them locally in the project folder. If you don't want to commit the JARs to the git repo (size and/or permission being a problem), you can just copy them into the Project folder after cloning. While they're not there, you'll be shown a warning, but once Eclipse can find them, everything's fine.

M2E Removes My Source Directory?

I have an existing library that I am building in Eclipse and have added the Maven nature to my project using m2e to add dependencies. When I convert it to a Maven project, my existing source directory (and my bin) become normal folders. Is there a reason for this? I am new to Maven, so I am likely doing something wrong, just not sure what...
My project structure is as follows:
workspace
project
src (in build path)
resources (in build path)
bin (output dir)
I tried both "mvn eclipse:eclipse" and right click on project -> Configure -> Convert to Maven Project, and both removed my src and resources folders from my build path, and after changing the structure to the below, changed the output to target/test-cases. Even if I manually adjust the build path and output, my dependencies don't resolve.
workspace
project
src (no longer in build path)
resources (no longer in build path)
bin (no longer output)
target (new output dir)
test-cases (empty)
I think you have the following structure when working with Eclipse (without Maven):
/workspace
/project1
.project
/src
/bin
But Maven want to use the following structure
/workspace
/project1
.project
pom.xml
/src
/main
/java
/resources
/test
/java
/target
/classes
/test-classes
and so on. So it is normal, that the folder src is no more directly a source folder for Eclipse, but now there are src/main/java, src/main/resources, ...
So it would be easier in the beginning to start with a new Maven project, and move your original sources to the directories they should belong to. Maven has a long tradition with its "convention over configuration", to deviate from that is possible. Have a look at the answer to "Handling unconventional source directory ..." to fix this.

Resources