I try upgrade my application from Grails 2.4.4 to Grails 3.0.2 and I have problem with spring annotation.
I have controller, like this:
import grails.plugins.springsecurity.annotation.Secured
class MyController {
#Secured(['ROLE_ADMINS_GROUP'])
def index() {
// some code
}
}
In depencencies block in build.gradle I have this:
dependencies {
provided 'org.springframework.boot:spring-boot-starter-logging'
provided "org.springframework.boot:spring-boot-starter-actuator"
provided "org.springframework.boot:spring-boot-autoconfigure"
provided "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.springframework.boot:spring-boot-starter-security"
provided "org.grails:grails-web-boot"
provided "org.grails:grails-dependencies"
provided 'javax.servlet:javax.servlet-api:3.1.0'
testCompile "org.grails:grails-plugin-testing"
console "org.grails:grails-console"
compile "org.grails.plugins:wslite:0.7.2.0"
}
When i try compile my application, I get error message.
MyController.groovy: 4: unable to resolve class grails.plugins.springsecurity.annotation.Secured
# line 4, column 1.
import grails.plugins.springsecurity.annotation.Secured
^
Spring Security Core Plugin has already been updated and is now compatible with Grails 3.0 see the docs: What's New in Version 3.0
Just add following dependency to the dependencies block of the build.gradle file:
compile "org.grails.plugins:spring-security-core:3.0.0.M1"
Related
I have a java project based on Spring framework, which is based on gradle build tool.
The gradle configures a parent project Par and sub-project Child.
The Par project has the build.gradle setting spring framework boot version as 2.2.6:
plugins {
id 'org.springframework.boot' version '2.2.6.RELEASE'
...
}
The Child project has the build.gradle as below:
ext.versions = [
spring: '5.2.9.RELEASE',
spring_boot: '2.2.10.RELEASE',
slf4j: '1.7.30',
grpc_helpers_java: '^19.0'
]
I tried to use WebClient of spring framework, so I added spring-boot-starter-webflux dependency to the build.gradle file of the child project as below:
dependencies {
...
compile group: 'org.springframework.boot', name: 'spring-boot-starter-webflux', version: versions.spring_boot
...
}
I don't have other code change yet.
However, although the build passed, the bootRun from the Par project failed with the following error:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory.createHttpServer(NettyReactiveWebServerFactory.java:163)
The following method did not exist:
'reactor.netty.transport.Transport reactor.netty.http.server.HttpServer.runOn(reactor.netty.resources.LoopResources)'
The method's class, reactor.netty.http.server.HttpServer, is available from the following locations:
jar:file:/C:/Users/XXX/.gradle/caches/modules-2/files-2.1/io.projectreactor.netty/reactor-netty/0.9.12.RELEASE/41022546d07f1499fb9d8617bba4a1a89d3549db/reactor-netty-0.9.12.RELEASE.jar!/reactor/netty/http/server/HttpServer.class
The class hierarchy was loaded from the following locations:
reactor.netty.http.server.HttpServer: file:/C:/Users/XXX/.gradle/caches/modules-2/files-2.1/io.projectreactor.netty/reactor-netty/0.9.12.RELEASE/41022546d07f1499fb9d8617bba4a1a89d3549db/reactor-netty-0.9.12.RELEASE.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of reactor.netty.http.server.HttpServer
I think the transitive dependency reactor.netty has a version of 0.9.12 is correct based on the spring-boot-starter-webflux version of 2.2.10. So I do not understand why the bootRun is trying to look for reactor.netty.http.server.HttpServer.runOn method which doesn't exist for reactor.netty version 0.9.12
Thank you very much.
I'm trying to get Mapstruct working with gradle. The implementations generate and work great when I run the service from the boot dashboard in eclipse, but they don't generate when run with gradlew bootrun, and the bean can't be found. Here is the error:
*************************** APPLICATION FAILED TO START
Description:
Field fooMapper in ServiceImpl required a bean of type 'FooMapper'
that could not be found.
The injection point has the following annotations:
- #org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'FooMapper' in your configuration.
And here is my build.gradle file:
plugins {
id "org.springframework.boot"
id "groovy"
id "com.diffplug.eclipse.apt" version "3.31.0"
}
configurations {
// configuration to enable running bootRun locally
// with embedded h2 database
runlocal
}
ext {
mapstructVersion = "1.5.0.Beta1"
}
dependencies {
implementation "org.mapstruct:mapstruct:${mapstructVersion}"
annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
testImplementation "org.testng:testng:6.10", "org.easytesting:fest-assert:1.4"
implementation project(":common")
implementation "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
implementation "org.springframework.boot:spring-boot-starter-jdbc:$springBootVersion"
implementation "org.springframework.boot:spring-boot-starter-data-jpa:$springBootVersion"
implementation "org.springframework.boot:spring-boot-starter-actuator:$springBootVersion"
implementation "org.springframework.boot:spring-boot-starter-validation:$springBootVersion"
implementation "org.codehaus.gpars:gpars:1.2.1"
developmentOnly "org.springframework.boot:spring-boot-devtools:$springBootVersion"
runlocal project(":test-db")
testImplementation project(":test-db")
}
sourceSets.main.groovy.srcDirs += ["build/generated/sources"]
bootRun {
classpath = sourceSets.main.runtimeClasspath + configurations.runlocal
}
tasks.withType(JavaCompile) {
options.compilerArgs = [
"-Amapstruct.suppressGeneratorTimestamp=true",
"-Amapstruct.defaultComponentModel=spring",
"-Amapstruct.verbose=true"
]
}
Is it because my code is written in groovy? But then why would it work with the boot dashboard in eclipse? I am using #Mapper(componentModel = 'spring'), but that hasn't fixed the issue. Using version 1.4.2.FINAL also doesn't work. Any help would be really appreciated!
had the same problem in eclipse, solved configuring my project properties:
Go to:
Java Compiler > Annotation Processing
Set Enable Project specific settings to true
Go to:
Java Compiler > Annotation Processing > Factory Path
Add external jar:
Here find the location of your mapstruct-processor-1.4.2-Final.jar on the gradle cache directory, i am using debian 11, my path is on:
/.gradle/caches/modules-2/files-2.1/org.mapstruct/mapstruct-processor/1.4.2.Final/e55bd90d51cddd638c07d5bd89fc7535d4e3d069/mapstruct-processor-1.4.2.Final.jar
Apply and close, and gradle should rebuild the project, generating two new folders .apt_generated and .apt_generated_tests on the package explorer with the mapper code
I'm learning spring boot with Kotlin (since I come from Android with Kotlin). I set it up with gradle. In my local machine everything works just fine. But I'm having a few issues while trying to deploy it to Heroku.
This is the error I'm getting:
Error: Main method not found in class com.markoid.packit.PackitApplication, please define the main method as:
2021-07-01T20:58:51.075484+00:00 app[web.1]: public static void main(String[] args)
2021-07-01T20:58:51.075581+00:00 app[web.1]: or a JavaFX application class must extend javafx.application.Application
I read on other posts that I need to add system.properties file in the root, so I did, but nothing changes.
system.properties
java.runtime.version=11
And this is my build.gradle.kts
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "2.5.1"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
kotlin("jvm") version "1.5.10"
kotlin("plugin.spring") version "1.5.10"
}
group = "com.markoid"
version = "1.0.0-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11
repositories {
mavenCentral()
}
dependencies {
// Spring Boot Core
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-mail")
implementation("org.springframework.boot:spring-boot-starter-data-mongodb")
// Joda Time library
implementation("joda-time:joda-time:2.10")
// Json Web Token
implementation("io.jsonwebtoken:jjwt-impl:0.11.1")
implementation("io.jsonwebtoken:jjwt-api:0.11.1")
implementation("io.jsonwebtoken:jjwt-jackson:0.11.1")
// Serializers
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
// Documentation
implementation("io.springfox:springfox-swagger2:2.6.1")
// Kotlin related
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
// Testing Frameworks
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "11"
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.withType<Jar> {
manifest {
attributes["Main-Class"] = "com.markoid.packit.PackitApplication"
}
}
My app file is as simple as this:
#SpringBootApplication
class PackitApplication
fun main(args: Array<String>) {
runApplication<PackitApplication>(*args)
}
Does someone know what I'm missing? This is the first project on spring I'm trying to deploy on heroku, so please bare with me.
Thank you in advance.
I've faced with the same issue. My problematic configuration is:
Kotlin 1.5.21
Spring boot 2.5.2
Gradle 7.1.1
The problem was that in IDEA it can be run, but cannot not using gradlew command line. I went and checked all old projects. They were built and run without any problem. The difference was in versions. All my previous project had lower versions in all positions I mentioned above. So I suggested that the problem was in the version, but what tool it was? Kotlin, Spring, Gradle? I have not yet found the guilty (and no time to go into deep of this problem now), but I found a solution.
If you open your jar file in any archiver (eg. WinRAR) and look at the MANIFEST.MD you will see a line starting with 'Start-Class', there is your main class and it must end with 'Kt' suffix, for example
Start-Class: me.sigest.fiveplus.FiveplusApplicationKt
In my failed jar it was not. To fix it I changed the code in build.gradle.kts file and set
springBoot {
mainClass.set("com.example.MyMainClassKt")
}
Despite the fact that in reality my class is called MyMainClass (without suffix Kt) and it helped
P.S. all my old boot jars contain the correct name of main class with Kt. I suppose the problem is in Gradle
I just had to a few things to make it work:
In the build.gradle.kts, I removed the tasks with type jar, and added this:
springBoot {
mainClass.set("com.markoid.packit.PackitApplicationKt")
}
I needed to add a Procfile, with the following:
web: java -Dserver.port=$PORT $JAVA_OPTS -jar build/libs/packit-1.0.0-SNAPSHOT.jar
Such file will tell heroku the specific command I want to be executed to run the generated jar.
Have you tried changing the main method like it is being suggested in the error message, i.e. public static void main(String[] args)
The Situation
I have a Groovy subclass of a Java class. The Java class is from a dependency, not my own local package:
// A basic idea of the Java class' construction
public class JavaArea<PS, S> {
public JavaArea(PS initialStyle, BiConsumer, S otheStyle, Biconsumer) {
// constructs class...
}
}
class GroovyArea extends JavaArea<Collection<String>, Collection<String>> {
GroovyArea(Object unrelated arguments) {
super(Collections.emptyList(), defaultBiConsumer, otherStyle, defaultBiConsumer)
// do some other stuff to GroovyArea's fields
}
}
For some reason, the compilation of the class fails with:Constructor call must be the first statement in a constructor despite the constructor call being the first statement...
Exception executing
org.gradle.api.internal.tasks.compile.ApiGroovyCompiler#7a1c5b43
in compiler daemon:
org.gradle.api.internal.tasks.compile.CompilationFailedException:
Compilation failed; see the compiler error output for details..
super(Collections.emptyList(), otherParams)
^
The Gradle Build files
I have the following build file for the root project:
subprojects {
apply plugin: 'groovy'
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.6'
testCompile "org.spockframework:spock-core:1.0-groovy-2.4"
testRuntime "cglib:cglib-nodep:3.2.3"
testRuntime "org.objenesis:objenesis:2.4"
}
}
... and the following build file for the actual module containing the error:
version '1.0-SNAPSHOT'
apply plugin: 'groovy'
repositories {
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
dependencies {
compile 'org.codehaus.groovyfx:groovyfx:0.4.0'
compile project(':diagrammer')
compile group: 'org.reactfx', name: 'reactfx', version: '2.0-M5'
compile group: 'org.fxmisc.wellbehaved', name: 'wellbehavedfx', version: '0.3'
compile (group: 'org.fxmisc.richtext', name: 'richtextfx', version: '1.0.0-SNAPSHOT') {
exclude group:'org.reactfx', module: 'reactfx'
}
}
My Question
What's causing the problem and how do I fix it? Is this a bug with Groovy? Or an issue with my build environment?
IDE: IntelliJ 2016.1.3
I don't think it's the IDE because it performs syntax highlighting correctly and provides the correct documentation when I hover over the 'super' keyword
Gradle: Gradle 2.12
Groovy: Groovy 2.4.6
What I have tried
I've tried changing the versions of Gradle (via sdkman) and then Groovy (via build file). None of these have fixed the problem:
Gradle: 2.12, 2.14
using Groovy: 2.4.5, 2.4.6, 2.4.7
Updates
Creating a new Gradle project in IntelliJ that only has the necessary components to rebuild the GroovyArea class will fail with the same exception when I run gradle build.
Looks to be a bug in Groovy. Filed as GROOVY-7868
I have a Spring Boot project which uses "blessed" dependencies via the Gradle plugin. The dependencies block in my build.gradle file looks like this:
dependencies {
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.springframework.boot:spring-boot-starter-data-jpa"
compile "com.fasterxml.jackson.core:jackson-core"
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-csv"
}
(I've removed several other dependencies for brevity.)
The above code is broken because Spring Boot does not have a "blessed" version for the dataformat-csv extension.
All I want to do is get it to use the Spring Boot-derived version for jackson-core and use it for the jackson-dataformat-csv as well for consistency. How do I get the version number for that dependency if it's been derived by a plugin?