Log4j conflicts- container provided and project level - maven

We got a couple of grails applications running, each with its own Log4j classes.
They need to be moved with a server that has log4j provided by Tomcat.
It it possible to get the grails applications to use the tomcat provided libraries?
Any help would be appreciated.

You can try excluding log4j from Grails depencies so that Tomcat provided log4j will be used:
grails.project.dependency.resolution = {
inherits("global") {
excludes "log4j"
}
}

Related

Spring-boot BOM does not contain a dependency for tomcat-dbcp

Spring-boot BOM does not contain a dependency for tomcat-dbcp.
I have a Spring MVC project where I use a database connection pool for Hibernate ORM connections. This project is deployed in Tomcat. In my IntelliJ Idea development environment I use Tomcat embedded, by using the spring-boot-starter-tomcat. But the spring-boot-starter-tomcat does not define a dependency to tomcat-dbcp. Hence I decided to explicitly define a dependency to tomcat-dbcp in my build.gradle.kts file.
I had hoped that the Spring-boot BOM would have contained tomcat-dbcp, so that I would not need to specify it's version number and rely on the Spring Boot dependency management system to handle it's version number for me. But the Spring-boot BOM does not contain a dependency for tomcat-dbcp. Can Spring-Boot add it?
I came up with the following hack so as to not hard code the version number for tomcat-dbcp. Just added the following code to the build.gradle.kts file after dependencies section.
configurations.all {
resolutionStrategy.eachDependency {
if (requested.group == "org.apache.tomcat.embed" && requested.name == "tomcat-embed-core") {
dependencies {
providedRuntime("org.apache.tomcat", "tomcat-dbcp", requested.version) //to use tomcat connection pool in tomcat embedded mode.
}
}
}
}

How to use JPA metamodel with gradle, intellij IDEA?

I am using java 8, spring boot 2.0.0, spring-data-jpa(spring-boot-starter-data-jpa), gradle, intellij. I've been trying to use JPA Metamodel, but having difficulty on finding how to configure.
Metamodels for Entity classes aren't just generated.
I guessed it would be simple, but now it seems that can be wrong. How can I use it?
JDK11 / Gradle 5.0 / Hibernate 5.3.7.Final
sourceSets.main.java.srcDirs += "${buildDir}/generated"
compileJava {
options.annotationProcessorGeneratedSourcesDirectory = file("${buildDir}/generated")
}
dependencies {
annotationProcessor("javax.xml.bind:jaxb-api")
annotationProcessor("org.hibernate:hibernate-jpamodelgen")
}
Generated Metamodel classes will be generated at 'build/generated'
If you are using JDK8 or Hibernate 5.4+, annotationProcessor("javax.xml.bind:jaxb-api") may unnecessary.
I did this the other day using the scalified metamodel gradle plugin (https://plugins.gradle.org/plugin/com.scalified.plugins.gradle.metamodel). I'm using Spring Boot 2.0.5, but I don't see why it wouldn't work the same with Spring Boot 2.0.0. I'm using Gradle 4.8.1 as well.
Below is an excerpt of my build.gradle.
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath (
"org.springframework.boot:spring-boot-gradle-plugin:2.0.0",
"gradle.plugin.com.scalified.plugins.gradle:metamodel:0.0.1");
}
}
apply plugin: "com.scalified.plugins.gradle.metamodel"
// The plugin will default to the latest version of Hibernate if this is not specified
metamodel {
hibernateVersion = '5.2.14.Final' // For Spring Boot 2.0.0
hibernateVersion = '5.2.17.Final' // For Spring Boot 2.0.5
}
This builds the metamodal files under src/generated and they can be used in your code. I had to also change an IntelliJ setting because IntelliJ's Build Automatically excludes some Gradle tasks that could be long running. See Automatically run Gradle task in project build with IntelliJ IDEA and https://youtrack.jetbrains.com/issue/IDEA-175165 for more details.
This setting I changed to overcome this is: Preferences->Build/Execution/Deployment->Gradle->Runner->Delegate IDE build/run actions to Gradle. An alternative would be to run the metamodelCompile gradle task manually as needed. That would lessen the time to rebuild by a little if you aren't frequently change your entities.

How to specify the Launcher in Spring Boot Gradle?

There three launcher in Spring Boot: JarLauncher/PropertiesLauncher/WarLauncher.
For executable jar, JarLauncher will be used by default. Now I want to use PropertiesLauncher instead so that I could use external classpath. How could I specify that is spring boot gradle plugin?
Accoring to D3.1 of this doc D.3.1 Launcher manifest, I can specify the main class in MANIFEST.MF like this:
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.mycompany.project.MyApplication
However, in Spring Boot Gradle, the following code snippet actually specifies the Start-Class, not the Main-Class:
springBoot {
mainClass = "com.sybercare.HealthServiceApplication"
}
Do I need to create the MANIFIEST.MF manually or there is a better way to do this?
Thanks!
Add the layout property:
springBoot{
mainClass = "com.sybercare.HealthServiceApplication"
layout = "ZIP"
}
layout = ZIP Triggers SpringBoot to use the PropertiesLauncher
The layout property defaults to a guess based on the archive type (jar or war). For the PropertiesLauncher the layout is ZIP (even though the output might be a jar file).
https://docs.spring.io/autorepo/docs/spring-boot/1.2.0.M2/maven-plugin/usage.html
The other answers are outdated now. The current answer seems to be:
tasks.getByName<BootJar>("bootJar") {
manifest {
attributes("Main-Class" to "org.springframework.boot.loader.PropertiesLauncher")
}
}
as per https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#packaging-executable.configuring.properties-launcher

Spring Boot not starting Jetty when using bootRun

In our current app we want to use Jetty instead of Tomcat in our Spring Boot app. As i read in the documentation excluding tomcat and introducing Jetty would be enough.
build.gradle
dependencies {
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
compile("org.springframework.boot:spring-boot-starter-jetty")
}
But when i try to run the app with using:
# gradle bootRun
Tomcat is indeed gone, but Jetty is not started and the application just terminates with any noticeable error. Any hints on what i am doing wrong?
Works well for me with Boot 1.1.0.RELEASE.
You need to run Gradle command with --info(--debug) hint to get more info what's going on.

Using Camel 2.1 with Grails 1.2.1 - Classloading problem

I'm trying to define a Camel context in my Grails application.
resource.groovy:
xmlns camel: 'http://camel.apache.org/schema/spring'
camel {
camelContext(id:'camelContext') {
}
}
Results in a stacktrace containing:
2010-02-03 13:24:42,209 [main] ERROR spring.GrailsRuntimeConfigurator - [RuntimeConfiguration] Unable to load beans from resources.groovy
org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NoClassDefFoundError: org/apache/camel/spi/ManagementStrategy
The strange thing is that ManagementStrategy is in lib/camel-core-2.1.0.jar. I'm not that familiar with neither Spring nor Camel so any suggestions are welcome. Can this be a classloader issue?
Read the release notes for Apache Camel 2.1
http://camel.apache.org/camel-210-release.html
There is a section with new .jar dependencies.
You need commons-management .jar on the classpath.

Resources