I create an kotlin library and published into maven central.
However, if this library is used by pure java project, user must add the dependency “kotlin-stdlib” explicitly.
It looks like that the “koitlin-stdlib” is automatically excluded from grade/maven dependency tree because it is treated as provided dependency.
How to resolve this problem?
In gradle you can add
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
The generated pom.xml should contain this dependency.
See:
https://mvnrepository.com/artifact/io.github.ragin-lundf/bdd-cucumber-gherkin-lib/1.48.0
-> under runtime dependencies
https://github.com/Ragin-LundF/bbd-cucumber-gherkin-lib/blob/main/build.gradle
-> as an example how to generate the pom for publishing to maven central in gradle
I find the reason.
implemetation(kotlin("reflect"))
is not OK,
api(kotlin("reflect"))
must be used.
Related
I have a gradle project P which has module A and B. Module A has this jackson dependencies:
...
dependencies {
...
compile 'com.fasterxml.jackson.core:jackson-core:2.12.0-rc1'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.12.0-rc1'
compile 'com.fasterxml.jackson.core:jackson-databind:2.12.0-rc1'
compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.12.0-rc1'
...
}
...
and module B uses module A, and has no need for including this dependencies because jackson usage is encapsulated in module A. But when code executed from module B reaches a statement that invokes code from Module A using it, I get exception:
java.lang.NoClassDefFoundError: com/fasterxml/jackson/dataformat/xml/XmlMapper
If I add the same dependencies to Module's B gradle.build file, the code works.
The question is, why would I include them if Module A does not use the library?
Shouldn't dependencies in Module A be compiled, packaged, so that when Module A is used elsewhere, its code works (using its included dependencies such as jackson library as in this example)
Disclaimer: I don't know Gradle, but this sounds like a problem common to Maven and Gradle.
The fact that you can build the module, but not run the module, means that somewhere you are not bringing the transitive dependencies into the Spring Boot fat jar. Jackson doesn't do anything weird with metadata files, classloaders, etc. It plays well with others in a fat jar.
Given that you haven't shared much of your build files, the easiest way to figure out if something has excluded the Jackson XML module is to just run jar -xvf target/app.jar and inspect the output to see if it's in there.
If it's not, look for a Gradle equivalent of the Maven dependency plugin's dependency-tree target that will show you the whole transitive dependency tree. If it's being excluded you'll definitely see it missing from a dependency dump.
I know maven dependencies have different scopes.
But what is Managed Dependencies?
The dependency you are looking at is not a jar file but a pom.xml that is meant to be used as "bom" (bill of materials). It contains the preferred versions of dependencies, so you would not need to inherit from that parent pom to use those version numbers but you can import them. See BOM section in the introduction: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#bill-of-materials-bom-poms
if you look into that pom.xml file: https://search.maven.org/artifact/org.apache.logging.log4j/log4j/2.13.3/pom you will see the dependencyManagegement section. If you import that pom that section is added to your own dependencyManagement secion (sort of). Its not dependencies yet, just preferred versions.
these kind of dependencies can only be added into the dependencyManagement section of the pom.xml - I assume the gradle dependency resolution follows that behaviour but I'm not sure about that, bom support took a while in gradle to be supported.
I am trying to use NetCDF-Java Library in Scala but got
sbt.librarymanagement.ResolveException: unresolved dependency: edu.ucar#cdm;4.6.11: not found
I have already tried manipulate with sbt.version (now is set to 1.1.1).
How to use this library in Scala?
The library you are looking for was not published to one of the standard repositories SBT uses by default.
It was published to the boundlessgeo repository as you can see on the mvnrepository page.
You need to add the repository to the resolution in your build file:
resolvers += "boundlessgeo" at "https://repo.boundlessgeo.com/main/"
maven allows you to define in pom file:
(A) dependencies -> the actual direct dependencies of the project
(B) dependencyManagement/dependencies -> managed dependencies that affect dependencies of category (A) with undefined version and transitive dependencies.
If I put wrong/unknown artifact on category A - maven will surely fail.
If I put wrong/unknown artifact on category B - maven will fail only if it affects category A (for instance, A defines dep on foo:bar and B defines dep on foo:bar:<unknown-version>.
I wonder if there is any existing plugin that will allow me to verify all managed deps (category B) - make sure they actually exist.
I have 1 global pom project with deps management that serves multiple projects and I want to verify any change to the deps in the CI before uploading new version to remote repository
In maven dependency plugin there is goal dependency:analyze-dep-mgt. You may use it to check dependencies in dependencyManagement section of your pom.xml.
If you need deeper control or more functionality, options would be to create your own plugin or have a dummy project which would use all your managed dependencies (although I should say this is a cumbersome solution).
I have a java gradle project. I have a dependency.
dependencies {
compile project(":mymodule")
compile 'org.springframework:spring-context:4.1.2.RELEASE'
}
Where can I find and use exact jar file name of both my custom module and spring dependency jar to process it further in composing application's libs, folders, etc?
Stick this in a new task:
project.configurations.compile.each{ println it}
Or, for just one specific dependency:
println project.configurations.compile.find {it.name.startsWith("something") }
However, if you're looking to create distributable packages including dependencies, you really should look into the gradle application plugin.