Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle with Integrated SQL Security

I'm currently working on converting one of our Maven projects to use Gradle. Here is the issue I'm currently facing:

This project is using SQL Integrated security. Here is how Maven handles it (this took us a while to figure it out):

    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>sqljdbc4</artifactId>
        <version>4.0</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/libs/sqljdbc4.jar</systemPath>
    </dependency>

after run gradle init --type pom this specific dependency has been converted to something like this:

system group: 'com.microsoft.jdbcdriver', name: 'sqljdbc', version:'4.0.1'

which is not right. Gradle can't build. More specifically, the system scope does not even exist in Gradle's API (neither I found it in any third party Gradle plugin).

Any help from whom had any experience with Gradle SQL integrated security would highly appreciated.

like image 905
CharlesC Avatar asked Oct 30 '22 22:10

CharlesC


1 Answers

It is very easy to emulate scope system with Gradle by adding a configuration.

Create configuration system and set it as the compile classpath. Any dependencies added to system will now be available during compilation (though I doubt you need a specific JDBC driver for compilation), but the dependencies in system will not be added to the published dependencies of the module:

configurations {
    system.extendsFrom compile
}

sourceSets {
    main {
        compileClasspath = configurations.system
    }
}

Now you can easily add the JAR of the JDBC driver to the system configuration. This assumes you still want to refer to a local file just like with Maven:

dependencies {
    system files('libs/sqljdbc-4.0.1.jar')
}

But if you have the JAR in a (local) repository, it is better to use the repository:

dependencies {
    system 'com.microsoft.jdbcdriver:sqljdbc:4.0.1'
}
like image 81
Johan Stuyts Avatar answered Nov 08 '22 04:11

Johan Stuyts