简体   繁体   中英

IntelliJ with gradle gives inconsistency in compilation

I'm writing Minecraft Plugin using IntelliJ IDEA Ultimate with gradle. I have added dependency org.spigotmc:spigot-api:1.13.2-R0.1-SNAPSHOT as compileOnly . During development, I noticed that gradle compiles my code in different way than IntelliJ does. For example, IntelliJ was unable to accept addPassenger on Boat , but gradle compiled it. In the opposite way, if I changed it into setPassenger , IntelliJ didn't mark it as error, but gradle failed to compile. I tried to invalidate caches, reimport, clean, even remove %userprofile%\\.gradle directory, nothing helped. As a POC I changed compileOnly to compile and it worked well, IntelliJ and gradle compilation results were consistent. What's the reason?

Ok, I found the solution (and forgot about this question).

I had been using multiple dependencies, and one load another with older version that I loaded implicitly in my build.gradle . However, they weren't exactly the same dependencies, but parallel ones. So gradle could not choose higher version of one dependency. Solution was to exclude this one explicitly loaded dependency and everything worked well.

Before:

dependencies {
    compileOnly 'com.sk89q.worldedit:worldedit-bukkit:7.0.1'
    compileOnly group: 'org.spigotmc', name:'spigot-api', version: '1.15.1-R0.1-SNAPSHOT'
}

After:

dependencies {
    compileOnly('com.sk89q.worldedit:worldedit-bukkit:7.0.1') {
        exclude `org.bukkit:bukkit:1.15.1-R0.1-SNAPSHOT`
    }
    compileOnly group: 'org.spigotmc', name:'spigot-api', version: '1.15.1-R0.1-SNAPSHOT'
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM