Gradle script for custom web project - java

I have a web project with 2 src folders. First is in businessServices >> commonServices and Second is in iSo >> src .
Now i have to write gradle script to build this project. i want a war and jar to deploy on tomcat.. Since this is not the standard gradle project, I am unable to generate the same. Please help.
I have added the screenshots to get the idea of project structure.

I think multi-src project is not a feasible solution, U can go with multi-project build.
Multi-project builds helps with modularization. It allows a person to
concentrate on one area of work in a larger project, while Gradle
takes care of dependencies from other parts of the project.
https://guides.gradle.org/creating-multi-project-builds/

Related

Maven Project Repository of Jar libraries

I'm trying to add Maven to already existing java project. It's been quite an adventure. I've read many questions here but I don't quite get it. The app I'm building is kinda modular so I'm loading many classes from URL so that the need of replacing the .exe (wrapped jar) file is at its minimum (Cuz once opened by any user I'cant update - replace the app (.exe)).
Since I'm using wide variety of libraries and the app Jar, hense the .exe, became too large - ~80MB, and slow to open from fileshare. Hense the need of Maven (or so I think). Since I installed Maven I had to add package statement at the top of every class, because before then there was not such thing, nor the need for it. Maven found the dependencies online and for the most part the process was not so time consuming, but the goal is to load the libraries from the project(app) folder /lib/. There I have all the libraries in jar files that I need. My question is: Is there a need of installing the libraries to local m2 directory (as I've read) since the app should always load them from the app folder? How do I configure the POM so the project/lib/ directory is recognized as a repo (or even is this the right approach), and load the libraries from the relative path of the project folder?
Thanks in advance to anyone able and willing to help!
Maven's core objective is to manage dependencies. You can add a dependency to your project, by configuring it in pom.xml, maven will download the dependency from the maven central repository & when building the project, maven can help you create a runnable JAR that have all your dependencies & code compiled.
Let's say in your current project if all of the dependencies are absolutely necessary, then even after migrating the project to maven, you're runnable JAR will remain the same size. There won't be any reduction in your application size. However, I would highly recommend migrating your project to any build tool like gradle or maven to manage project dependencies.

Java add .jar files automatically as a a Library

I am creating a java project in IntelliJ (without maven or grandle). The project uses an external library, whose .jar file I’ve put into a /lib directory. After that I had to select at the /lib folder “add as library” to use it.
Now I want to push the project to GitHub, so that some people (who are using IntelliJ as well, but in different versions) can use the project.
Now my question:
Is there a way, that they do not have to do the step “add as a library” themselves?
My first idea was to push also some parts of the .idea folder to GitHub, but I am not sure which ones to push and if that could actually work (especially with different versions of IntelliJ).
Do you have any idea how to solve this issue?
If you are using only IntelliJ for building the project, then yes, you should push the .iml files from the .idea folder (or where they happen to be), since they contain the dependencies configured in IntelliJ.
Note, that projects with multiple contributors typically use a build tool like Maven or Gradle.
This is a special build requirement, which I would use Gradle for. With Gradle you can look up a given folder, like /lib and use all .jar files as dependency.
See Gradle example about exactly what you want.
IntelliJ is handy when you do something simple mostly for learning, but if you want to be a professional one day I highly suggest looking into Gradle. It has a learning curve for sure, but you can achieve such simple tasks like this in your question relatively simply. And as you seem to know, pushing .idea to the repository is really not the nicest thing one can do :)
Just a small additional note: Gradle solves the "different version" problem by including a "Gradle wrapper" inside the repository, so everyone cloning the repository will have the same copy of Gradle as well, so the same build process is guaranteed for all contributors.
Also, when I started programming I downloaded the dependencies and used them as jars. But if you learn at least Maven, and your dependency is uploaded to a repository like Maven Central, you can just paste a line of code into your pom.xml (Maven) or build.gradle (Gradle) and you are good to go :)

Combining a maven project with a java project

Currently, I have a maven project that has a server running (using Jersey REST API). I also have a java project, I need to move all the contents of the java project into the maven project. The maven project is a subset of the java project. However, the maven project only displays the parts of the java project. However, I want a project that allows me to use maven and displays all of the other details from the java project.
I would've copied and pasted however I'm using git so I want to also preserve history.
I was thinking it would be easier to nest the maven project inside the java project but I don't know if that's possible.
Here's a picture of my package explorer to help explain everything.
Package explorer showing the maven project being a subset of the java project.
What I've tried is converting the java project into a maven project and then updating the pom.xml but then it doesn't link to the web.xml. Also, it tries to run the server with the name of the project name TeamProject. When infact it should run the url with the name client_server
I was considering just copying and pasting all the code into the maven project (from the Teamproject java project).
Actually nesting the java project inside the Maven project makes more sense, as it is the purpose of Maven to handle a project lifecycle. (also by default Maven will look for sources in the src/ folder which should ease the task of putting your Java project inside Maven's hands)
There are several possibilities I would see:
Copy your java project in the src/ of your client project and update maven accordingly (within the pom.xml)
Make your Java project a Maven project and aggregate the two projects in a parent pom (see Multi module maven project example)
Make your Java project a Maven project, and decide of a "Master" project between it and the client and compose one with the other (not sure that's a great solution)
Nesting your Maven project inside the Java project would not be so great because Maven could only handle the client and not your Java project, and then you'd miss on numerous functionalities offered by Maven (just look at how simple it is to get dependencies compared to downloading a jar and including it on the build path manually)

Git repository to Gradle dependencies

I am developing a project in java, using eclipse, making backup by git (Bitbucket), and I decided to use build it using gradle.
Some of my source code can be used by other project, so I want to move them to other project and manage with another git repository. I want to add them as a dependency to the original project. What should I have to write in build.gradle?
Here are the docs you need. Basically you need to create a standalone gradle project from the separate part. And then with the usage of settings.gradle create a multi project build. Maybe git modules will be also useful.

Include java project into android build

I've got such a problem
I have to include external java project into my android build.
The project structure is:
Alpha - project with shared classes and libs.
Beta - android project that uses files from alpha
Gamma - desktop java project that uses files from alpha.
Everything works fine on Eclipse, but I need it to work on Jenkins.
I'm using Google Android SDK (android update project command) to create a build.xml, and then I'm using google targets to do what I need (build, emma, clean and so on)
The problem is that this build.xml does not include files and libs from alpha project, so it basically failes at first line of beta build task.
My question is:
How to properly add alpha project as a dependency for a googles generated build.xml file?
Should I compress alpha to .jar and then add it somehow to beta (how?)
Should I just link it somehow?
Thanks for all help.
[I'm new to ant scripting so please write in plain engish:P]
Yep, this sucks! When using Jenkins and sharing one lib-project on different projects, you'll have to compile your lib-project (alpha), as you already mentioned, copy the jar to the respective directory of both projects, and link them in the Build Path Settings.
This is quite a lot of ANT-Stuff, you'll have to look into, but don't get discouraged, it ain't rocket science :)
Basically you have to do this:
Create an Ant-script that compiles your shared project, and copies it to some lib-directory in both projects
Link the Jar in the Build Path of your desktop and android project
For Jenkins: Customize android's build.xml (e. g. add a new target), so that it executes the lib project's build.xml (compile the project and copy the jar).
Run it on Jenkins
If you don't want to compile the shared project (manually) each time before you run your android or desktop project in eclipse, you should add the shared lib's build.xml with the respective targets to the projects' builder settings (in Eclipse -> right click on Project -> Properties -> Builders -> add the new builder between the Java and the Android package builder).
Sorry dude, I don't know any other way. Maybe there is another solution out there, I haven't used Jenkins for a year.

Categories

Resources