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'
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 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.
I have useful java class files from a old project on my computer and would like to include them in a build.gradle script for a new project. I also am using a library off the Maven repository and a jar file on my computer. I'm only have problem with including the classes and no problem with either of the others. Here is the dependency block.
dependencies {
compile 'no.tornado:tornadofx:1.7.14' //works
compile files('../lib/opencv-320.jar') //works
compile files('../oldProject/com') } //seems ok in IntelliJ, but won't compile
By including the oldProject/com in this way IntelliJ is able to see the dependency and recognize the class. However, when proceeding to run the app, here is the error that suggests the package "util" and class "MultiArray" in oldProject/com are not being seen by the Kotlin compiler.
Information: Kotlin: kotlinc -jvm 1.2.21 (JRE 1.80_71-b15)
Error:(3,8) Kotlin: Unresolved reference util
Error:(18,17) Kotlin: Unresolved reference MultiArray
Here is the include line in the top level settings.gradle file
include ('../oldProject/com')
com is your top-level package and not the directory root. You have to add the dependency
compile files('../oldProject')
IntelliJ can detect directory prefixes, but Gradle does not do that.
I have a java class which does some kind of functionality, one of these function returns something that I need to use it into gradle script to set the project properties.
I had achieved it by creating an artifact of project and used that artifact by adding it into classpath, that gave me accessibility of that class and function.
buildscript {
repositories {
jcenter()
maven{
url 'http:localhost:8081/artifactory/temp'
}
}
dependencies {
classpath "utility:sampleutility:1.0"
}
}
import com.polsys.utility.MyUtil
dependencies {
compile 'org.slf4j:slf4j-api:1.7.13'
compile 'HRP:'+new MyUtil().callMe()+':1.0'
//callme function returns the name of artifact.
testCompile 'junit:junit:4.12'
}
Now, I had achieved it by the way as mentioned above that is by creating artifact, add that artifact into classpath, then import classes and use function. Is this any way by which I can call functions of current project? so I can merge that functionality which is available in the artifact into current project.
Simple way is to put your Java/Groovy code under buildSrc dir. Gradle will compile it and you'll be able to call this code from your buildscript. Check https://docs.gradle.org/current/userguide/custom_plugins.html and related docs.
To make your java code available to gradle script you need to have your java code under the directory hierarchy given below:
ProjectRootDirectory
buildSrc
src
main
groovy/java
YourPackages(in my case java packages and classes)
This is the path where gradle script looking for external plugins. Now you can import and access classes into gradle script(you will not end up with "unable to resolve class" error).
I have a gradle build that relies on a plugin (MyTools) which is compiled in the buildSrc directory. This part is working correctly. The issue I'm having is trying to import a class from an external jar to use in the myTools plugin's source.
My Directory Structure looks like this:
buildSrc
---build.gradle
---MyTools
-----build.gradle
-----settings.gradle
-----libs
-------yuicompressor-2.4.6.jar
-----src
-------main
---------groovy
-----------com
-------------my
---------------MyTools.groovy
---------------MyToolsPlugin.groovy
---------resources
-----------META-INF
-------------gradle-plugins
-------------gradle-plugins/MyTools.properties
The contents of MyTools/build.gradle are:
dependencies {
runtime fileTree(dir: 'libs', include: '*.jar')
}
When I try to import com.yahoo.platform.yui.compressor.CssCompressor from MyTools.groovy, I get this message:
"unable to resolve class com.yahoo.platform.yui.compressor.CssCompressor"
Can somebody please tell me what I'm doing wrong?
You need to add a compile dependency, not a runtime dependency. Also, I don't see how the main build is going to pick up the plugin, given that it's located in a MyTools subdirectory (and buildSrc doesn't have a settings.gradle). Probably best to lift up MyTools into buildSrc.