I generated spring boot kotlin project with spring initializer in intellij.
And added lib dependency in build.gradle.kts after auto generated.
Implementation "org.springframework.boot:spring-boot-starter-security".
I tried import WebSecurityConfigureAdapter, but intellij is 'No suggestions'.
I could not import class after added in build.gradle.kts.
And i tried Run Configurations build, buildDependents, clean, etc...
How can I fix?
Refer to Kotlin Gradle DSL specification. Use
implementation("org.springframework.boot:spring-boot-starter-security:2.2.6.RELEASE")
to declare dependencies.
Related
Using gradle, in a projectA we import the resteasy BOM:
compile platform('com.fasterxml.jackson:jackson-bom:2.13.2')
compile 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
Then in a projectB we import projectA
implementation("com.my.service:projectA:0.0.1-SNAPSHOT")
Now, when we compile projectB, jackson-datatype-jsr310 cannot be found. It cannot determine the version to use. Same if in projectB I want to import another jackson dependencies, that are defined in the BOM.
How can I automatically use the same version in projectB?
The compile scope is not inherited transitively by projects that use your module as a dependency.
To set a transitive dependency (being a BOM or of any other kind) you should use the api scope.
However, note that for using the api scope, you need to tell Gradle that your project is a library (and not an executable module). To do this, you should add the java-library plugin.
Your project A should be defined this way:
plugins {
id 'java-library'
}
dependencies {
api platform('com.fasterxml.jackson:jackson-bom:2.13.2')
api 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
}
You can check all the details at the java-library plugin documentation.
I have a Gradle multi-module project where each module have a CompilerScript.groovy similar to this:
import groovy.transform.CompileStatic
withConfig(configuration) {
ast(CompileStatic)
imports {
star('jakarta.inject')
}
}
Each Gradle module is configured to read this file and it works as expected.
compileGroovy.groovyOptions.configurationScript = file('src/compiler/groovy/CompilerConfig.groovy')
But IntelliJ show errors inside editor about missing import statements. There is a way
to configure the Idea Gradle Plugin with the same configs as Gradle? Thanks.
In gradle plugin I wrote
project.configurations.create("myConf")
But when I import my plugin into project and write myConf("smth:smth:smth") the compiler doesn't recognize myConf
Well, the project with that plugin couldn't resolve my custom configuration at compile time.
I had to declare a variable val myConf = configurations.getByName("myConf") and then I could use it
I have a gradle 4.1 multiproject containing a "projectA" containing 2 subfolders "api" and "implementation".
The multiproject uses kotlin and java-library plugins defined in the subprojects section of the main build.gradle.
The implementation project avec a API dependency to :projectA:api
In the api folder I have kotlin and java files inside 'src/main/java' and in the implementation project I'm creating a new instance of a kotlin class from the API.
Inside Intellij Idea, I don't have any compilation errors ; but when I compile the whole project using gradle I have an error: cannot find symbol. It is as if the compileJava doesn't have access to the folder kotlin-classes.
Inside the build/kotlin-classes, I see my file.class
The class file is on build/classes dir also
Details of the error :
Task :projectA:api:compileKotlin
Using kotlin incremental compilation
Task :projectA:implementation:compileJava
(...) error: cannot find symbol (the import fails)
Update 1 : removing java-library solved my problem
This is a known issue of the java-library plugin: when used in a project with another JVM language (Kotlin, Scala, Groovy etc.) , it does not register the classes of the other language so that the dependent projects get them as they consume the classes.
Fortunately, it has a workaround as well. Adapted to Kotlin, it would look like:
configurations {
apiElements {
outgoing.variants.getByName('classes').artifact(
file: compileKotlin.destinationDir,
type: ArtifactTypeDefinition.JVM_CLASS_DIRECTORY,
builtBy: compileKotlin)
}
}
If you use Kapt1, it's file: compileKotlinAfterJava.destinationDir, and for Gradle versions lower than 4.0 use builtBy: copyMainKotlinClasses instead.
This issue is also tracked in the Kotlin issue tracker: KT-18497, follow that issue to see when it's fixed on the Kotlin Gradle plugin side, so that the above workaround will be no more necessary.
I cant seem to get this (github_link) class imported into my gradle groovy project for testing (Unable to resolve class compile error), Even though the package is coming up in eclipse
import org.openehealth.ipf.platform.camel.ihe.ws.StandardTestContainer
I have the testCompile dependency to the containing jar from jcenter (link)
testCompile 'org.openehealth.ipf.platform-camel:ipf-platform-camel-ihe-ws:3.3.0'