TypeToken not found

Hi everybody,

I have a couple of ideas for some plugins on sponge.
Since I already did some android programming I decided to use gradle but for some reason I can’t get it to work.
The error I get while I try to rebuild or build an artifact:

java: cannot access com.google.common.reflect.TypeToken
class file for com.google.common.reflect.TypeToken

After some googling I noticed that this should happen when com.google.guava is missing but when I check the external libraries it is there.

It errors on the line:
config.getNode(“placeholder”).setValue(true);

this was just to test out the config.

My gralde.build file:

`group ‘ClanWars’
version ‘1.0-SNAPSHOT’

apply plugin: ‘java’

repositories {
mavenCentral()
maven {
name = ‘sponge’
url = ‘http://repo.spongepowered.org/maven
}
}

dependencies {
compile ‘org.spongepowered:spongeapi:4.1.0-SNAPSHOT’
}`

I have been struggling with this problem for 3 days and I am not getting any further :frowning:

Regards,
jokie666

Sponge has a Gradle plugin. Just add to your build.gradle

plugins {
    id 'org.spongepowered.plugin' version '0.5.2'
}

This does a bunch of the setup for you. All you need after that is group, version, and dependencies.
Second, 4.1.0 is officiallly released now. You can get rid of ‘-SNAPSHOT’.
Maybe for whatever reason, guava’s not on the classpath for the version 4.1.0-SNAPSHOT is currently representing.

I changed my build.gradle:

`plugins {
id “com.qixalite.spongestart” version “1.4.3”
id “org.spongepowered.plugin” version “0.6”
}

group ‘Clan Wars’
version ‘1.0-SNAPSHOT’
description = ‘An example plugin’

repositories {
mavenCentral()
maven {
name = ‘spongepowered-repo’
url = ‘Repository - Nexus Repository Manager
}
}

spongestart{
eula true

//optional configs
spongeVanillaBuild 'LATEST'
spongeForgeBuild 'LATEST'
forgeServerFolder 'run/forge'
vanillaServerFolder 'run/vanilla'

}

dependencies {
compile ‘org.spongepowered:spongeapi:4.1.0’
}`

But the error still exists :frowning:

Dont forget
4.1.0-SNAPSHOT

Wait, why? 4.1.0 is officially released.

Doesn’t matter, it doesn’t make any difference. The strange thing is that I have an example plugin which is exactly the same, except for the name, which works and I can’t find what differs.
Later this day I will post both codes, I am now on my phone.

Oh, I think you’re not allowed spaces in the group setting

1 Like

I just made a brand new project,
No spaces in the name and it gives exactly the same error.

apply plugin: 'java'
version = '1.0'
repositories {
    mavenCentral()
    maven{
        name 'Sponge maven repo'
        url 'http://repo.spongepowered.org/maven'
    }
}

dependencies {
compile “org.spongepowered:spongeapi:4.1.0”
}

my class:

package com.joris.clanwars.claim;
import com.google.inject.Inject;
import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.loader.ConfigurationLoader;
import org.spongepowered.api.config.ConfigDir;
import org.spongepowered.api.config.DefaultConfig;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.GamePreInitializationEvent;
import org.spongepowered.api.plugin.Plugin;
import org.slf4j.Logger;
import java.nio.file.Path;
@Plugin(id = "ClanWarsClaim", name = "ClanWarsClaim", version = "1.0")
public class Claim {
    @Inject
    private Logger logger;
    @Inject
    @DefaultConfig(sharedRoot = false)
    private Path defaultConfig;
    @Inject
    @DefaultConfig(sharedRoot = false)
    private ConfigurationLoader<CommentedConfigurationNode> loader;
    @Inject
    @ConfigDir(sharedRoot = false)
    private Path configDir;
    private ConfigurationNode config;
    @Listener
    public void preInit(GamePreInitializationEvent event){
        try{
            config = loader.load();
            if(!defaultConfig.toFile().exists()){
                config.getNode("placeholder").setValue(true);
                loader.save(config);
            }
        }catch (Exception e){
        }
    }
}

Again this line:
config.getNode(“placeholder”).setValue(true);
gives the error:
java: cannot access com.google.common.reflect.TypeToken
class file for com.google.common.reflect.TypeToken not found

I would like to get started but yeah… :frowning:

Well I gues its bumping time, bump :confounded:

Just out of curiosity, can you see what happens when you use this as a build.gradle for a brand new project?

plugins {
    id 'org.spongepowered.plugin' version '0.5.2'
}

group 'com.example'
version '1.0'

dependencies {
    compile 'org.spongepowered:spongeapi:4.1.0'
}

I made a brand new project called example, changed the build.gradle and added the same code. Gives me the same error once again.

First, is that error thrown only during compile time, or does the IDE report it? Second, what IDE are you using?

Thank you for the fast reaction,

It is during compile time, when I try to build an artifact of during rebuild.
I am using IntelliJ IDEA Community Edition. This is the first time I am using IntelliJ but I familiar with Android Studio which is almost the same.

I have to admit that’s odd. It’s possible you accidentally tweaked some setting in intellij (maybe?)

Assuming the control mappings are still the same, crtl->click on TypeToken (anywhere in your code) in intellij. See if the class actually exists in the environment somewhere.

The thing is, I don’t have typetoken anywhere in my code. It errors on config.getNode(“placeholder”).setValue(true);

Configurate internally uses TypeTokens unfortunately…

I know but when I ctrl+click it it goes to some interfaces, I can’t find the TypeTokens class manually but it is in the external libraries beneath the google guava

Can you post a screenshot of your plugin dependencies?

It didn’t want to upload to sponge directly so I used imgur

Does it compile when you run gradle build?
If not, try to clean gradle cache (USER_HOME/.gradle)