Make IntelliJ use modules not maven central jars

Hello.

I have recently switched from Maven to Gradle for this project, but that has caused a few issues on the development side. This project requires me to import 2 separate modules into IntelliJ at the same time. The “Trident” module depends on “TridentSDK”. The SDK is available on maven central, and here is where the problem comes in. If I import both of the Gradle modules into IntelliJ, it results in the following:

This is great and all, but as you can see, instead of trident resolving the sdk to the local module, it instead uses the maven central jar.

The only solution I can find is to tell Gradle to use the local module instead of the central one, however that means that you can’t compile the trident module from just its own source (it won’t pull the sdk from maven central)

When I used maven, it somehow just automagically realized that the jar its looking for is in the project and imported the local module instead.

Can you show your build.gradle file?

Sure

TridentSDK build.gradle:

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()

        maven { url "http://repo1.maven.org/maven2" }
        maven { url "http://repo.maven.apache.org/maven2" }
        maven { url "https://plugins.gradle.org/m2/" }
    }

    dependencies {
        classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.5.3"
        classpath "gradle.plugin.nl.javadude.gradle.plugins:license-gradle-plugin:0.14.0"
        classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
    }
}

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'io.codearte.nexus-staging'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'maven-publish'
apply plugin: 'jacoco'
//apply plugin: "com.github.hierynomus.license"

group = 'net.tridentsdk'
version = '0.5-SNAPSHOT'
archivesBaseName = "tridentsdk"

description = "TridentSDK"

sourceCompatibility = 1.8
targetCompatibility = 1.8

def ossrhUser = System.getenv("CENTRAL_USER")
def ossrhPassword = System.getenv("CENTRAL_PASS")

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

repositories {
    mavenLocal()
    mavenCentral()
    jcenter()

    maven { url "https://plugins.gradle.org/m2/" }
    maven { url "http://repo1.maven.org/maven2" }
    maven { url "http://repo.maven.apache.org/maven2" }
    maven { url "http://oss.sonatype.org/content/groups/public/" }
    maven { url "https://oss.sonatype.org/content/repositories/public/" }
}

dependencies {
    compile group: 'org.hjson', name: 'hjson', version: '3.0.0'

    compileOnly group: 'org.javassist', name: 'javassist', version: '3.22.0-CR2'
    compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.16.18'
    compileOnly group: 'com.esotericsoftware', name: 'reflectasm', version: '1.11.3'
    compileOnly group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'

    testCompile group: 'junit', name: 'junit', version: '4.12'
    testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '1.3'
    testCompile group: 'org.openjdk.jmh', name: 'jmh-core', version: '1.19'
    testCompile group: 'org.openjdk.jmh', name: 'jmh-generator-annprocess', version: '1.19'
    testCompile group: 'org.mockito', name: 'mockito-core', version: '2.8.47'
    testCompile group: 'org.objenesis', name: 'objenesis', version: '2.6'
}

task javadocJar(type: Jar) {
    classifier = 'javadoc'
    from javadoc
}

task sourcesJar(type: Jar) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

shadowJar {
    classifier = null
}

artifacts {
    archives javadocJar, sourcesJar, shadowJar
}

subprojects {
    artifacts {
        archives javadocJar, sourcesJar, shadowJar
    }

    test.useTestNG()
}

allprojects {
    apply plugin: 'java'
    apply plugin: 'maven'

    uploadArchives {
        repositories {
            mavenDeployer {
                repository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
                    authentication(userName: ossrhUser, password: ossrhPassword)
                }

                pom.project {
                    name project.name
                    description project.description
                    packaging 'jar'
                    url 'https://tsdk.xyz/'

                    scm {
                        connection 'scm:git:git://github.com/TridentSDK/TridentSDK.git'
                        developerConnection 'scm:git:git@github.com:TridentSDK/TridentSDK.git'
                        url 'https://github.com/TridentSDK/TridentSDK/tree/master/'
                    }

                    licenses {
                        license {
                            name 'Apache License 2.0'
                            url 'https://opensource.org/licenses/Apache-2.0'
                            distribution 'repo'
                        }
                    }

                    developers {
                        developer {
                            name = 'TridentSDK Team'
                        }
                    }
                }
            }
        }
    }
}

nexusStaging {
    username = ossrhUser
    password = ossrhPassword
}

jacocoTestReport {
    reports {
        xml.enabled true
        html.enabled false
    }
}

check.dependsOn jacocoTestReport

TridentSDK settings.gradle:

rootProject.name = 'tridentsdk'

Trident build.gradle:

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()

        maven { url "http://repo1.maven.org/maven2" }
        maven { url "http://repo.maven.apache.org/maven2" }
        maven { url "https://plugins.gradle.org/m2/" }
    }

    dependencies {
        classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.5.3"
        classpath "gradle.plugin.nl.javadude.gradle.plugins:license-gradle-plugin:0.14.0"
        classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
    }
}

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'io.codearte.nexus-staging'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'maven-publish'
//apply plugin: "com.github.hierynomus.license"

group = 'net.tridentsdk'
version = '0.5-SNAPSHOT'
archivesBaseName = "trident"

description = "Trident"

sourceCompatibility = 1.8
targetCompatibility = 1.8

def ossrhUser = System.getenv("CENTRAL_USER")
def ossrhPassword = System.getenv("CENTRAL_PASS")

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

repositories {
    mavenLocal()
    mavenCentral()
    jcenter()

    maven { url "https://plugins.gradle.org/m2/" }
    maven { url "http://repo1.maven.org/maven2" }
    maven { url "http://repo.maven.apache.org/maven2" }
    maven { url "http://oss.sonatype.org/content/groups/public/" }
    maven { url "https://oss.sonatype.org/content/repositories/public/" }
}

dependencies {
    compile group: 'net.tridentsdk', name: 'tridentsdk', version: '0.5-SNAPSHOT'
    compile group: 'io.netty', name: 'netty-codec', version: '4.1.13.Final'
    compile group: 'io.netty', name: 'netty-transport-native-epoll', version: '4.1.13.Final', classifier: 'linux-x86_64'
    compile group: 'com.esotericsoftware', name: 'reflectasm', version: '1.11.3'
    compile group: 'org.javassist', name: 'javassist', version: '3.22.0-CR2'
    compile group: 'org.fusesource.jansi', name: 'jansi', version: '1.16'
    compile group: 'org.jline', name: 'jline-reader', version: '3.3.1'

    compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.16.18'
    compileOnly group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'

    testCompile group: 'junit', name: 'junit', version: '4.12'
    testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '1.3'
    testCompile group: 'org.openjdk.jmh', name: 'jmh-core', version: '1.19'
    testCompile group: 'org.openjdk.jmh', name: 'jmh-generator-annprocess', version: '1.19'
}

task javadocJar(type: Jar) {
    classifier = 'javadoc'
    from javadoc
}

task sourcesJar(type: Jar) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

shadowJar {
    classifier = null
}

artifacts {
    archives javadocJar, sourcesJar, shadowJar
}

subprojects {
    artifacts {
        archives javadocJar, sourcesJar, shadowJar
    }

    test.useTestNG()
}

allprojects {
    apply plugin: 'java'
    apply plugin: 'maven'
    apply plugin: 'jacoco'

    uploadArchives {
        repositories {
            mavenDeployer {
                repository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
                    authentication(userName: ossrhUser, password: ossrhPassword)
                }

                pom.project {
                    name project.name
                    description project.description
                    packaging 'jar'
                    url 'https://tsdk.xyz/'

                    scm {
                        connection 'scm:git:git://github.com/TridentSDK/Trident.git'
                        developerConnection 'scm:git:git@github.com:TridentSDK/Trident.git'
                        url 'https://github.com/TridentSDK/Trident/tree/master/'
                    }

                    licenses {
                        license {
                            name 'Apache License 2.0'
                            url 'https://opensource.org/licenses/Apache-2.0'
                            distribution 'repo'
                        }
                    }

                    developers {
                        developer {
                            name = 'TridentSDK Team'
                        }
                    }
                }
            }
        }
    }
}

jar {
    manifest {
        attributes(
                'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
                'Main-Class': 'net.tridentsdk.server.TridentMain'
        )
    }
}

Trident settings.gradle

rootProject.name = 'trident'

Try to replace
compile group: 'net.tridentsdk', name: 'tridentsdk', version: '0.5-SNAPSHOT'
with
compile project(':tridentsdk')
and add this to settings.gradle
include ':tridentsdk' project(':tridentsdk').projectDir = new File(settingsDir, 'PASTE_HERE_PATH_TO_tridentsdk/tridentsdk')

Yes, that works, but then it doesn’t know it can pull from maven central

So, which one option your are trying to achive?

Both, I need it to detect if there is a module, then use the module, if there is no module, then pull from central

I think you’re looking for something like composite builds. This allows you to take two separate Gradle projects and stick them together as if they were one build.

Here are some other references:

User guide
Composite builds + IDEA
Webinar demonstrating composite builds (47 min)