SLF4J and Inject

Hey, so I’ve got two projects (A and B) both depending on google’s Inject and SLF4J. Project A is a maven project and project B is a Gradle project. Both projects had to have these libs added to the classpath of the project. So both projects are basically identical up until this point other than the build tool being used. I can not build project B (gradle project) without getting the error:

Executing external task ‘build’…

C:\some-hidden-path\SpearMod.java:3: error: package com.google.inject does not exist
import com.google.inject.Inject;
^
C:\some-hidden-path\SpearMod.java:8: error: package org.slf4j does not exist
import org.slf4j.Logger;
^
C:\some-hidden-path\SpearMod.java:19: error: cannot find symbol
private Logger logger;
^
symbol: class Logger
location: class SpearMod
C:\some-hidden-path\SpearMod.java:58: error: cannot find symbol
public Logger getLogger() {
^
symbol: class Logger
location: class SpearMod
C:\some-hidden-path\SpearMod.java:18: error: cannot find symbol
@Inject
^
symbol: class Inject
location: class SpearMod
C:\some-hidden-path\SpearMod.java:21: error: cannot find symbol
@Inject
^
symbol: class Inject
location: class SpearMod
C:\some-hidden-path\SpearMod.java:24: error: cannot find symbol
@Inject
^
symbol: class Inject
location: class SpearMod
7 errors
:compileJava FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:compileJava’.
    Compilation failed; see the compiler error output for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 0.512 secs
Compilation failed; see the compiler error output for details.
External task execution finished ‘build’.

I’ve compared the classpaths in IntelliJ 14 but I have been unable to deduce why I can build one and not the other. I am sure there’s a perfectly understandable solution but at this point in time I’m pretty stumped. Any advice/suggestions would be more than appreciated. I would prefer to use Gradle over Maven.

How have you configured your gradle.properties and settings.gradle?

Is gradle.properties per-project? I’ve never seen it before. Also all I have in the settings.gradle is the rootProject.name value.

Sorry I meant build.gradle I wasn’t sure of the name so I checked the spongeAPI repo, and got myself confused.

Here’s project A’s dependencies: http://prntscr.com/77sood.
Here’s project B’s dependencies: http://prntscr.com/77spk7.

They both have the required libs as far as I know.

EDIT: I’ve now made project B have the EXACT same dependencies as project A but it still says that slf4j and inject do not exist. They’re marked as provided, why does it “need” them?

Update


IDE: IntelliJ 14.1.3
Java Version: 1.8.0-u45
Gradle Version: 2.4

Okay, so I’ve attempted to invalidate my caches with IntelliJ. It resulted in SLF4J and Google Inject no longer being libs in my module. I only hit this issue with Gradle (not with Maven).

I’m at my wits end at this point. I’ve tried rearranging the dependencies, manually adding them etc. Is there something I’m missing in my build.gradle?

dependencies {
compile group: ‘org.spongepowered’, name: ‘spongeapi’, version: ‘2.1’, transitive: true, { ext { fatJarExclude = true } }
}

(it’s properly formatted in my actual file, the forums don’t want it to be on one line- at least in preview mode)

I know that the SpongeAPI does not uber-jar/shade/fatjar its dependencies, so perhaps I should somehow be marking my dependency of the API in a way so that it also depends on its dependencies?

I’m a n00b at Gradle, but I had no issue with the syntax for build.gradle on the Docs:

dependencies {
compile “org.spongepowered:spongeapi:2.1-SNAPSHOT”
}

https://docs.spongepowered.org/en/plugin/basics/workspace/dependencies.html

Note that there is no spongeapi version 2.1. There is only spongeapi 2.0 or 2.1-SNAPSHOT

1 Like

Great to know! Thanks :smile:

EDIT: I’ll see if that’ll help.

Still no luck. I’ve been trying everything I can. Instead of using my own remote repo I even used sponge’s and I still get this: http://prntscr.com/799q9l. I’ve tried all possible imports/adding etc and I can’t seem to get my Gradle project to build without it telling me Inject/SLF4J packages do not exist…

Here is what I would do.

  • In IntelliJ delete all your modules. Close the IDE
  • At the root of your plugin, run gradle clean build --refresh-dependencies
  • Import in IntelliJ as a module from existing sources. Choose your build.gradle

So I removed all my modules, closed my IDE, then I ran gradle clean build --refresh-dependencies on the module (or “project”) but I still get the same result from that command as shown in the OP.

Okay, so I resolved the issue for now. I had another dependency in the module that seems to prevent it from compiling giving off the error in OP. When I remove it I get no issues compiling. Although it’s an API and the plugin is the implementation so it needs to be able to be fatJar’d together, but then ALL the dependencies get fatJar’d.

EDITED