Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jdbi3-bom excludes spring-jcl in bom #2295

Closed
jedvardsson opened this issue Mar 16, 2023 · 1 comment · Fixed by #2300
Closed

jdbi3-bom excludes spring-jcl in bom #2295

jedvardsson opened this issue Mar 16, 2023 · 1 comment · Fixed by #2300
Assignees
Labels

Comments

@jedvardsson
Copy link

The jdbi3-bom excludes spring-jcl needed by org.springframework.boot.SpringApplication. I've submitted a sample Application.java and pom.xml below.

package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>spring-boot-with-jdbi3-fails</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.4</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <java.version>19</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- When this is included the spring-jcl dependency is excluded -->
        <!-- since the jdbi3-bom explicitly excludes it -->
        <dependency>
            <groupId>org.jdbi</groupId>
            <artifactId>jdbi3-spring5</artifactId>
        </dependency>

        <!-- a work around is to explicitly include spring-jcl -->
        <!--        <dependency>-->
        <!--            <groupId>org.springframework</groupId>-->
        <!--            <artifactId>spring-jcl</artifactId>-->
        <!--        </dependency>-->

    </dependencies>

    <dependencyManagement>
        <!--  dependencies not managed by spring boot parent need to be defined here  -->
        <dependencies>
            <dependency>
                <groupId>org.jdbi</groupId>
                <artifactId>jdbi3-bom</artifactId>
                <type>pom</type>
                <version>3.37.1</version>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

Expected result:

$ mvn clean package
$  unzip -l target/spring-boot-with-jdbi3-fails-1.0.0-SNAPSHOT.jar|grep spring-jcl
    23489  03-02-2023 17:30   BOOT-INF/lib/spring-jcl-6.0.6.jar
$ java -jar target/spring-boot-with-jdbi3-fails-1.0.0-SNAPSHOT.jar               

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.0.4)
...

Actual result:

$ mvn clean package
$ unzip -l target/spring-boot-with-jdbi3-fails-1.0.0-SNAPSHOT.jar|grep spring-jcl
$ java -jar target/spring-boot-with-jdbi3-fails-1.0.0-SNAPSHOT.jar 
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
        at java.base/java.lang.reflect.Method.invoke(Method.java:578)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:95)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
        at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:183)
        at com.example.Application.main(Application.java:10)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        ... 5 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
        at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:149)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
        ... 8 more
hgschmie added a commit to hgschmie/jdbi that referenced this issue Mar 20, 2023
Turns out that this actually makes using the jdbi bom in spring projects
harder.

Fixes jdbi#2295
@hgschmie hgschmie self-assigned this Mar 20, 2023
@hgschmie hgschmie added the bug label Mar 20, 2023
@hgschmie
Copy link
Contributor

Hi @jedvardsson,

Thank you for filing a bug report with the Jdbi project! This is indeed a problem and it will be fixed in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants