I have the following project structure. Gradle 3.1
RootProject
-- Project A <-- RESTful JAX-RS Project
-- Project B <-- Services Project containing EJB's
I want to assemble this project into one single WAR archive such as RootProject.war which would include Project A & B for deployment in an EAR archive (totally separate from this project).
How do I setup the root level build.gradle and the sub projects build.gradle files?
If I set the apply plugin: 'war' to the root build.gradle i get options for creating war archives from each project!
Related
I am trying to build ear using gradle build and ear is building fine.In my project ejb module is creating multiple custom jar along with ejb jar .How to add them onto ear root directory instead of adding them in lib folder
I am able to include them in ear lib folder but not in EAR root directory
EAR/APP-INF/lib/A.jar
should be EAR/A.jar
project(':A-project')
earproject(path: ':A-project',configurations:'provided')
earfiles(project(':A-project').tasks.findByName('ATask'))
Try adding deploy(A.jar) to your dependencies{} code block. This will create an ejb entry in the application.xml
build.gradle
dependencies {
deploy(A.jar)
}
Reference
dependencies
{
deploy project(path: ':A-Project')//jar files
deploy project(path: ':B-Project',configuration:'archives')//war files
deploy project(project(':C-Project').tasks.findByName("app"))//project in built jars
}
I had a http servlet application which was a multi project gradle build, where my project was a contain gradle HttpServlet project and it depends on the other two gradle java projects. I deployed all the 3 jars in the tomcat webapps/Web-INF/lib directory and run it.
Now there is a requirement that I have to convert my application as a spring boot application and instead of 3 separate jars I have to create a fat jar which I should run it.
I don’t have much experience with grade and spring boot. I was wondering how can I create a fat jar from the multi gradle project.?
I converted my http servlet project to a spring boot project but I am confused that how I will refer the other gradle projects in the springboot project and create a single fat jar? Please see the directory structure of the projects
Rootrepository
- Springboot project
-src….
- OtherGardleProject1
- Src…
- OtherGardleProject2
- Src…
Can someone please share some pointer?
You could use a top-level settings.gradle file that includes the main app and the libraries
Rootrepository
- settings.gradle
- Springboot project
- build.gradle
-src….
- OtherGardleProject1
- Src…
- OtherGardleProject2
- Src…
The settings.gradle looks like this:
include: ':Springboot project', ':OtherGardleProject1', ':OtherGardleProject2'
Then in the build.gradle of the Springboot project module you add the dependencies to the libraries
plugins {
id 'org.springframework.boot' version '2.0.3.RELEASE'
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
...
dependencies {
compile project(':OtherGardleProject1')
compile project(':OtherGardleProject2')
...
}
After you build the project, the jar in Sprinboot project/build/libs folder should contain the classes of the app and the other two modules as jar files.
Hope it helps.
I have a multi module project with the following structure:
root_project
module1
module2
module3
I try to apply the java plug-in to all projects using the following code:
allprojects {
apply plugin: 'java'
group = 'com.mysoftware'
sourceCompatibility = 1.8
version = '1.3'
repositories {
mavenCentral()
}
}
Additionally I add the javafx plugin to module3. The java and javafx tasks are now shown in the intellij gradle view, but when trying to execute them, I get this error:
Task 'jfxJar' not found in root project 'module3'.
Furthermore, running the tasks task show me that neither the java tasks nor the javafx tasks are available, despite being shown in the gradle view in intellij.
I tried rebuilding and refreshing the whole project without success. I use the Use default gradle wrapper configuration.
The error message you got Task 'jfxJar' not found in root project 'module3' indicates that Gradle considers the subproject module3 as a Root project: this can happen if you created a settings.gradle file in the sub-project directory, which is not a valid setup (only one settings.gradle file can exist in a multiproject build, located in the root directory)
Currently I have two projects with gradle build.gradle. The first is going to create a fat jar file, which I would like to include in a war file. I thought compiling it would be enough, but it doesn't seem to be ending up in the /lib directory of my war file. Anyone have thoughts I am quite new to gradle.
dependencies {
compile project(':JarProject')
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
providedCompile 'org.apache.tomcat:tomcat-jsp-api:7.0.55'
}
war {
archiveName 'WarProject.war'
from 'JarProject/build/libs'
webXml = file('src/web.xml')
}
Does the second project war need to be in providedRuntime? Or should I publish the jar from the other project in the local maven repo and include it that way?
The War task essentially behaves like a CopyTask with regards to stuff it packs in the war, so the documentation on working with files is useful. In essence, I think you need something like (untested):
from fileTree('JarProject/build/libs') {
into("lib")
}
That being said, using mavenLocal() and publishing there also works, but it can lead to unexpected results when the war includes some old version from local, picking up the jar explicitly from the file system like above is better.
I think the elegant solution would be to use multi project builds and project level dependencies. You would have the two builds as separate projects of the same Gradle build and add the "jar project" as a regular compile dependency.
How have you declared the dependency? I assume you have a multi-project build with subprojects A and B, both using the War plugin. I made an experiment using Gradle 2.4 and if I declare B/build.gradle like this:
apply plugin: 'war'
dependencies {
compile project(':A')
}
then B.war contains WEB-INF/lib/A.jar. If you correctly follow conventions of Gradle War plugin (place web resources in A/src/main/webapp/ and code-related resources in A/src/main/resources/), then A.jar should contain what you want.
see this
My web app is build using two projects one that contains the api and second web part. In Eclipse I am able to use classes from project-api in project-web however in deploy I have exception:
Caused by: java.lang.ClassNotFoundException: project.api.TestApi
This is my main build.gradle file:
sourceCompatibility = 1.7
subprojects {
apply plugin: 'java'
}
This is build.gradle from api:
apply plugin: 'java'
apply plugin: 'eclipse'
repositories {
mavenCentral()
}
dependencies {
}
And this is part of my build.gradle from web:
dependencies {
compile project(':project-api')
...
}
If I go and see web app libraries I can't see anything like project-api.jar. Wham am I doing wrong?
UPDATE:
It is issue only in eclipse. If I run gradlew war and deploy this manually to tomcat I can deploy it without any issued. project-api.jar is included in war. I tried already to run few times
`gradlew clean cleanEclipse eclipse`
but it doesn't help. I also try to reimport projects in eclipse but still the same.
EDIT:
This project is a spring mvc app and I just discovered that when I build war from gradle I am able to deploy war manually without any errors. Issue is only when trying to deploy via eclipse.
EDIT: Here is settings.gradle
rootProject.name = 'project'
include 'project-test'
include 'project-web'
include 'project-api'
You need to convert the dependencies of the deployable project to a "faceted project".
Project properties -> Project Facets -> Convert to faceted form...
Then mark each dependency as a "Utility Module".