How to use kotlin-bom - maven

I have a single-module maven project which uses a number of Kotlin libraries, and I'm trying to specify the kotlin-bom to ensure they all use the same version. I've got the following in my pom.xml:
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-bom</artifactId>
<version>1.6.20</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</dependency>
...
However, when I do mvn compile, I get this error:
[ERROR] 'dependencies.dependency.version' for org.jetbrains.kotlin:kotlin-stdlib-jdk8:jar is missing.
How can I use kotlin-bom in a single-module project?

Move your bom declaration to dependencyManagment section
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-bom</artifactId>
<version>1.6.20</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</dependency>
</dependencies>

Related

Can a Maven BOM contain another Maven BOM?

Can a Maven BOM(BOM1) contain another BOM(BOM2) in its dependencyManagement? If yes, how could the usage of BOM1 through inclusion in a pom.xml can use the dependencies from BOM2 in a project? Thanks in advance!
To better explain the situation, the below works when i include both of the in the pom.xml of the service:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>my.custom.bom</groupId>
<artifactId>my.custom.bom</artifactId>
<version>${my.custom.bom.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Whereas the following does notwhen I include it in the pom.xml of the service:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>my.custom.bom</groupId>
<artifactId>my.custom.bom</artifactId>
<version>${my.custom.bom.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
And the my.custom.bom in the second situation includes the spring-boot-dependencies like so:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
To summarize when pom.xml includes BOM1 and BOM2 works, but when pom.xml includes BOM1 and BOM1 includes BOM2 no longer works.

dependecy not found: openfeign

I get the error:
Could not find artifact org.springframework.cloud:spring-cloud-openfeign:pom:unknown in central (https://repo.maven.apache.org/maven2)
Here is my pom.xml
<?xml version="1.0" encoding="UTF-8"?>
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.4.0
privas.microservice
sellcar
0.0.1-SNAPSHOT
sellcar
Demo project for Spring Boot
<properties>
<java.version>15</java.version>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.source>${java.version}</maven.compiler.source>
<spring-cloud.version>Hoxton.SR8</spring-cloud.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
It is a module project if that information is needed.
Does anyone know why maven doesn't find openfeign? It also doesnt work with any other spring cloud dependency.
org.springframework.cloud has 2 packages:
spring-cloud-starter-openfeign
spring-cloud-openfeign-core
but not spring-cloud-openfeign

Why override org.webjars when using org.springframework.cloud dependency management?

Why override org.webjars when using org.springframework.cloud dependency ? there is any dependency vise versa? I am confused .
See below snippet:
In pom.xml file:
override dependencies:
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap-datepicker</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>datatables</artifactId>
<version>1.10.19</version>
</dependency>
when i am using below dependency:
<project>
......
<!-- Some dependencies -->
.....
<dependencies>
......
.......
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Edgware.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
......
<!-- Some dependencies -->
.......
</project>
This post explained exact problem: Overriding managed version 3.2.0 for bootstrap when put <dependencyManagement>
Please help me.

Why including bom doesn't work?

I found something doesn't work that I expected to work.
I imported the org.glassfish.jersey:jersey-bom in my dependencyManagement section.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>2.26-b03</version>
<type>pom</type>
<scope>include</scope>
</dependency>
</dependencies>
</dependencyManagement>
That pom clearly includes following dependency.
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>${project.version}</version>
</dependency>
Now I add my own dependency
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
And mvn complains.
'dependencies.dependency.version' for org.glassfish.jersey.core:jersey-common:jar is missing. # line 33, column 17
What's wrong with my pom?
Did you define project-version as a property? I guess not, since you're not using it to specify the version of your BOM.
Using the literal string, this should work:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>2.26-b03</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.26-b03</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
</dependency>
</dependencies>
What intrigues me is that you shouldn't need to specify org.glassfish.jersey.core:jersey-common:2.26-b03 in <dependencyManagement> since it is part of the BOM, but the dependency doesn't work if it is not there.

Calling KieScanner throws ClassNotFoundException

I have several Drools projects and would like to be able to dynamically load rules changes. The projects all work fine until I tried to add KieScanner to them. I followed the directions here: http://docs.jboss.org/drools/release/6.0.1.Final/drools-docs/html/DroolsReleaseNotesChapter.html#d0e515
I am using drools 6.1.0.Final with Wildfly 8.0.0.Final
The documentation indicates that having the dependency for the kie-ci in my class path was enough. Clearly either I am doing something wrong or the documentation is wrong.
The project builds but when it is called, I get this trace:
10:21:17,946 ERROR [io.undertow.request] (default task-2) UT005023: Exception handling request to /catalog/vetec/search/facets/term: org.jboss.resteasy.spi.UnhandledException: javax.enterprise.inject.CreationException
at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:76) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:149) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:372) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179) [resteasy-jaxrs-3.0.6.Final.jar:]
Caused by: java.lang.NoClassDefFoundError: org/apache/maven/repository/internal/MavenRepositorySystemSession
at org.kie.scanner.MavenRepository.getMavenRepository(MavenRepository.java:73) [kie-ci-6.1.0.Final.jar:6.1.0.Final]
at org.kie.scanner.ArtifactResolver.(ArtifactResolver.java:36) [kie-ci-6.1.0.Final.jar:6.1.0.Final]
at org.kie.scanner.KieRepositoryScannerImpl.getArtifactResolver(KieRepositoryScannerImpl.java:87) [kie-ci-6.1.0.Final.jar:6.1.0.Final]
at org.kie.scanner.KieRepositoryScannerImpl.getArtifactVersion(KieRepositoryScannerImpl.java:108) [kie-ci-6.1.0.Final.jar:6.1.0.Final]
at org.drools.compiler.kie.builder.impl.KieRepositoryImpl$KieModuleRepo.load(KieRepositoryImpl.java:281) [drools-compiler-6.1.0.Final.jar:6.1.0.Final]
at org.drools.compiler.kie.builder.impl.KieRepositoryImpl$KieModuleRepo.load(KieRepositoryImpl.java:267) [drools-compiler-6.1.0.Final.jar:6.1.0.Final]
at org.drools.compiler.kie.builder.impl.KieRepositoryImpl.getKieModule(KieRepositoryImpl.java:90) [drools-compiler-6.1.0.Final.jar:6.1.0.Final]
at org.drools.compiler.kie.builder.impl.KieRepositoryImpl.getKieModule(KieRepositoryImpl.java:77) [drools-compiler-6.1.0.Final.jar:6.1.0.Final]
at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:97) [drools-compiler-6.1.0.Final.jar:6.1.0.Final]
at com.sial.rules.cdi.KSessionContextProvider.(KSessionContextProvider.java:49) [sial-rules-0.0.1-SNAPSHOT.jar:]
Here is the pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sial.rules</groupId>
<artifactId>sial-rules</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>JBoss Repository</id>
<url>https://repository.jboss.org/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<!-- Added to ensure that we have the correct DROOLS/JBOSS versions -->
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-bom</artifactId>
<version>6.1.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>jboss-javaee-7.0-with-tools</artifactId>
<version>8.0.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>jboss-javaee-7.0-with-resteasy</artifactId>
<version>8.0.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-decisiontables</artifactId>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-persistence-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>knowledge-api</artifactId>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-internal</artifactId>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-ci</artifactId>
<exclusions>
<exclusion>
<groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.0-rc1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.drools</groupId>
<artifactId>drools-maven-plugin</artifactId>
<version>6.0.0.CR5</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
This business rules project is itself incorporated into the actual WARs that are deployed to Wildfly.This is the dependency used in the application poms:
<dependency>
<groupId>com.sial.rules</groupId>
<artifactId>sial-rules</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
I recently discovered that the extra dependency breaks our Arquillian Unit tests. Since Arquillian has a completely different maven integration, my best guess is that this is a bug in KIE. It is very similar to BZ1098018
Adding this extra dependency "fixes" the issue when the code actually calls kie-ci, however with this dependency our Arquillian tests fail to deploy.
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-aether-provider</artifactId>
<version>3.0.5</version>
</dependency>
You should not need to declare the additional maven, aether and other dependencies manually. The kie-ci should transitively depend on everything it needs. If you look at the pom.xml of the kie-ci https://github.com/droolsjbpm/drools/blob/6.1.0.Final/kie-ci/pom.xml the dependencies you added are also listed there, so Maven resolves them automatically.
This seems to be either some weird bug or misconfiguration. I presume you have the following in your pom:
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-ci</artifactId>
<version>6.1.0.Final</version>
</dependency>
Could you post your whole pom?
The problem is that kie-ci includes an older version of maven (3.0.5) than does Arquillian (3.1.1) Specifically the maven-aether-provider. Arquillian (really ShrinkWrap) really wants to use the newer version.
I tried forcing the 3.0.5 version in the pom.xml but get the issue of the resolver.
This is the error:
java.lang.UnsupportedOperationException: Unable to boostrap Aether repository system. Make sure you're running Maven 3.1.0 or newer.
So basically kie 6.1.0.Final is incompatible with Arquillian 1.1.5.Final
I will have to see if the Kie 6.2.0CR3 release will work

Resources