java.lang.NoClassDefFoundError with apache dbcp2 in gradle

365 Views Asked by At

I recently created a class which uses BasicDataSource from dbcp2, however when i try to use methods from this class, i get the java.lang.NoClassDefFoundError: org/apache/commons/dbcp2/BasicDataSorce error even though i have the dependency added in my build.gradle: enter image description here

What could be causing this issue, and how could i fix it ?

Class which uses BasicDataSource

import org.apache.commons.dbcp2.BasicDataSource;

import java.sql.Connection;
import java.sql.SQLException;

public class DatabaseUtils {

    private static final BasicDataSource dataSource = new BasicDataSource();

    static {
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://localhost:3306/test");
        dataSource.setUsername("username");
        dataSource.setPassword("password");
    }

    public static Connection getConnection() throws SQLException {
        return dataSource.getConnection();
    }

}
0

There are 0 best solutions below