Grails 4: Is spring-security-ldap updated for Grails 4.0? - grails

I am upgrading my Grails 3.3.2 application to Grails 4.0.0.RC2 and all references to org.springframework.security.ldap classes are unresolved. I'm not sure if this is a matter of waiting for a later version of the plugin or if there's something different I should be doing for Grails 4. If I need to wait for a later version, is there an ETA on this?
I'm using this version in my build.gradle file:
compile "org.grails.plugins:spring-security-ldap:3.0.2"
Here's an example of some unresolved errors:
unable to resolve class org.springframework.ldap.core.DirContextOperations
unable to resolve class org.springframework.ldap.core.DirContextAdapter

Due to Gradle change:
Separation of compile and runtime dependencies when consuming POMs
To use some Grails 3 plugins in Grails 4 apps you need to include their transitive dependencies directly. Otherwise they are not brought into the classpath.
The fix is to include the dependencies directly in your build.
ext {
springSecurityVersion="5.1.6.RELEASE"
springSecurityCoreVersion="4.0.0.RC2"
springSecurityLdapVersion="3.0.2"
}
dependencies {
...
// Security
compile "org.grails.plugins:spring-security-core:$springSecurityCoreVersion"
compile ("org.grails.plugins:spring-security-ldap:$springSecurityLdapVersion") {
exclude group: 'org.grails.plugins', module:'spring-security-core'
}
compile "org.springframework.security:spring-security-ldap:$springSecurityVersion", {
['apacheds-core', 'apacheds-core-entry', 'apacheds-protocol-ldap', 'apacheds-protocol-shared',
'apacheds-server-jndi', 'commons-logging', 'fest-assert', 'jcl-over-slf4j', 'junit',
'ldapsdk', 'logback-classic', 'mockito-core', 'shared-ldap', 'slf4j-api', 'spring-beans',
'spring-context', 'spring-core', 'spring-ldap-core', 'spring-security-core',
'spring-test', 'spring-tx'].each { exclude module: it }
}
compile 'org.springframework.ldap:spring-ldap-core:2.0.4.RELEASE', {
['commons-lang', 'gsbase', 'junit', 'mockito-core', 'powermock-api-mockito',
'powermock-api-support', 'powermock-core', 'powermock-module-junit4',
'powermock-module-junit4-common', 'powermock-reflect', 'slf4j-log4j12', 'spring-beans',
'spring-core', 'spring-data-commons', 'spring-test', 'spring-tx'].each { exclude module: it }
}
I took the transitive dependencies from the plugin:
https://github.com/grails-plugins/grails-spring-security-ldap/blob/master/build.gradle#L63-L76

Related

How to import a proprietary library in Grails 4.0.3

I am trying to import a proprietary jar lib (ICOMConector.jar) in my grails 4.0.3 project, but it is sending me an error.
In IntelliJ, I right-clicked the project folder and accessed Open Module Settings. Then I clicked in Libraries and chose my jar. Right after, clicked in Module / Dependencies and chose that jar in a compilation scope.
In build.gradle file I put this flatDir, because the jar in my project grails stardard structure:
repositories {
maven { url "https://repo.grails.org/grails/core" }
flatDir {
dirs 'lib'
}
}
And this in the same build.gradle, I've tried all of that, including those now commented,
but the error persists.
dependencies {
//implementation name: 'lib/ICOMConector.jar'
//runtime files('lib/ICOMConector.jar')
//runtime fileTree(dir: 'lib', include: '*.jar')
compile fileTree(dir: 'lib', include: ['*.jar'])
}
when I send grails run-app in the command line, the error is:
| Running application...
startup failed:
/media/alfredo/1TBHDD/CMB/Code projects/Grails 4/detran-mspid/grails-app/init/detran/mspid/BootStrap.groovy: 5: unable to resolve class com.workers.icom.ICOMConector
**# line 5, column 1.
import com.workers.icom.ICOMConector
^
1 error**
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileGroovy'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
I tried to instantiate the class in Bootstrap.groovy, to make it easier to verify if it is working as expected.
Could anyone help me to import this library. A friend of mine did this in a Spring boot project and it worked, so the problem seems to be a wrong configuration in Grails.
package detran.mspid
import com.workers.icom.ICOMConector
class BootStrap {
def init = { servletContext ->
ICOMConector icom = new ICOMConector()
}
def destroy = {
}
}
This is what I have in my build.gradle for using a library in grails 4.0.3 (been this way since at least grails 3, though). This is almost identical to one you tried with runtime scope.
compile files("lib/opencsv-2.3.jar")
runtimeOnly fileTree(dir: './lib', include: ['*.jar'])
It's entirely possible that either one or both of those is unnecessary...

Grails : How to migrate dependencies upgrading from 2.x.x to 3.0.8?

I am attempting to upgrade an existing Grails application from version 2.4.4 to 3.0.8. I have a couple issues that I am currently unable to resolve.
First issue: The old version's BuildConfig.groovy referenced a jar file that was in the lib directory. I tried copying the same configuration from BuildConfig.groovy to build.gradle and created a lib directory with the jar but Grails is unable to resolve the dependency.
Second issue: The old version had a plugin defined. I tried copying the same plugin definition from BuildConfig.groovy into build.gradle, but this isn't working. I noticed that the plugin isn't currently listed in Bintray, is this the problem?
Below is the dependency section of the build.gradle file.
dependencies {
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-dependencies"
compile "org.grails:grails-web-boot"
compile "org.grails.plugins:hibernate"
compile "org.grails.plugins:cache"
compile "org.hibernate:hibernate-ehcache"
compile "org.grails.plugins:scaffolding"
compile "com.stripe:stripe-java:1.32.1"
compile "com.google.code.gson:gson:2.3.1"
compile "javax.mail:mail:1.4"
runtime "org.grails.plugins:asset-pipeline"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
// Note: It is recommended to update to a more robust driver (Chrome, Firefox etc.)
testRuntime 'org.seleniumhq.selenium:selenium-htmlunit-driver:2.44.0'
console "org.grails:grails-console"
//jar file located in lib directory
runtime "com.easypost:easypost-java:2.1.2"
//grails plugin
compile ":shiro:1.2.1"
}
Thanks in advance for any guidance provided.
Issue 1: If that jar is a standard jar and you can reference it from maven then that would be good. But still if you need to include it from some local directory then you can do this:
repositories {
flatDir {
//Directory path containing Jar
dirs 'libs'
}
}
dependencies {
//Jar File Name - No need to add suffix .jar
compile name: 'someJarFile'
}
Issue 2: If the plugin is not listed in bintray then that means it has not been upgraded for Grails 3.x. Either you can upgrade it for yourself or remove the plugin if possible.

Exclude Gradle dependency at debug

I'm using Grails plugin to execute (war and debug) Grails 2.5.0 project.
It seems one of dependencies contain older dependency than I would like to you. When I war a project correct version is used, but at debug it uses older dependenvy version:
dependencies {
bootstrap "org.grails.plugins:tomcat:7.0.50" // No container is deployed by default, so add this
// plugins for the compile step
compile "joda-time:joda-time:2.3"
compile("org.grails.plugins:spring-security-rest:1.5.2") {
exclude module: 'xml-apis'
exclude module: 'joda-time'
}
compile 'org.grails.plugins:cache:1.1.8'
// plugins needed at runtime but not for compilation
runtime ("org.grails.plugins:hibernate4:4.3.8.1") { exclude module: 'xml-apis' } // or ":hibernate:3.6.10.18"
runtime "org.grails.plugins:database-migration:1.4.0"
}
So at debug I have joda-time 1.6 which is shipped with spring-security-rest:1.5.2. But when war-ed joda-time version is 2.3

Replace a global library with a new version in Grails

Grails comes with Protobuf 2.4.1 as a 'global dependency', but my app uses a library that compiled against Protobuf 2.5.0 (and version 2.5.0 isn't compatible with 2.4.1).
The problem that I don't see any way to tell Grails to use only specified version instead of bundled. If I exclude it in BuildConfig it just excluded from application, all versions. I mean:
inherits("global") {
excludes 'protobuf-java'
}
dependencies {
//build 'com.google.protobuf:protobuf-java:2.5.0'
// or
compile 'com.google.protobuf:protobuf-java:2.5.0'
}
Grails fails with:
Fatal error during compilation org.apache.tools.ant.BuildException:
java.lang.NoClassDefFoundError: com/google/protobuf/MessageOrBuilder
How I can exclude global library, and add it as a new dependency instead? I'm using Grails 2.2.2
You do not need to exclude protobuf-java. The newest version, when provided as a dependency, should evict the older one. So v2.4.1 will be evicted by v2.5.0.
inherits("global") {
//excludes 'protobuf-java'
}
dependencies {
build 'com.google.protobuf:protobuf-java:2.5.0'
}
The above should be good. To witness the same, run a dependency-report on the grails app and look for the dependency.
To support with facts, I tested it and it works perfectly for me.
import com.google.protobuf.TextFormat
//Just to replicate your issue, but it did not complain about this import.
import com.google.protobuf.MessageOrBuilder
class BootStrap {
def init = { servletContext ->
TextFormat t = new TextFormat()
println t
}
def destroy = {
}
}
//Prints:
com.google.protobuf.TextFormat#372688e8

how to delete guilty jar file after grails dependency-report

when I tried to run grails -Dgrails.env=local run-app, I got the below error
Server failed to start: java.lang.LinkageError: loader constraint violation: loader (instance of ) previously initiated loading for a different type with name "javax/management/MBeanServer"
After analysing I understood that it has something to do with "Two dependencies link the same jar with different versions"
I ran grails dependency-report, and here is the observation:
commons-beanutils by commons-beanutils 1.8.3 release default false 227 kB
commons-beanutils by commons-beanutils 1.8.0 release default true 0 kB(evicted by 1.8.3)
How do I exclude this jar or remove the linkage?
The dependency report should show what is pulling in the problematic jar. Once you have that, explicitly exclude it from the dependencies in your BuildConfig.groovy, like so:
grails.project.dependency.resolution = {
dependencies {
runtime("i-depend-on-beanutils-1.8.3") {
excludes "beanutils"
}
}
}

Resources