Issue with importing a Gradle project for XNAT - unresolved type

140 views Asked by At

I trying to import a Gradle project for XNAT for the first time using Eclipse 2018-12. I created the project, right clicked, chose Gradle then Existing Gradle Project. After the import completed there is an error with SimpleUploadPlugin.java - "The type org.apache.ecs.ConcreteElement cannot be resolved. It is indirectly referenced from required .class files". I have checked and I have the commons-lang3-3.8.1.jar.

What do I need to do to resolve this issue please?

My build.gradle dependencies are:

// TODO: This is a pretty minimal set of dependencies, so don't worry if you need to add more.
dependencies {
    implementation("org.nrg.xnat:web") {
        transitive = false
    }
    implementation("org.nrg.xnat:xnat-data-models") {
        transitive = false
    }
    implementation("org.nrg.xdat:core") {
        transitive = false
    }
    implementation "org.nrg:prefs"
    implementation "org.nrg:framework"

    implementation("turbine:turbine") {
        transitive = false
    }
    implementation("org.apache.velocity:velocity") {
        transitive = false
    }
    implementation("stratum:stratum") {
        transitive = false
    }

    implementation "log4j:log4j"
    implementation "io.springfox:springfox-swagger2"

    compile group: 'ecs', name: 'ecs', version: '1.4.2'
}
2

There are 2 answers

2
Spanky Quigman On BEST ANSWER

Another option is to change the dependency configuration for org.nrg.xnat:web from compile or implementation to compileOnly. This lets you declare fewer dependencies for your plugin because you can allow transitive dependencies. The ECS dependency comes from classes in XNAT itself, so allowing the transitive dependencies means you don't have to declare everything that might be indirectly referenced. I just made this change in the XNAT LDAP authentication plugin and went from this:

implementation("org.nrg.xnat:web") {
    transitive = false
}
implementation("org.nrg.xnat:xnat-data-models") {
    transitive = false
}
implementation("org.nrg.xdat:core") {
    transitive = false
}
implementation("org.nrg:prefs") {
    transitive = false
}
implementation("org.nrg:framework") {
    transitive = false
}

implementation "org.springframework:spring-web"
implementation "org.springframework.security:spring-security-config"
implementation "org.springframework.security:spring-security-ldap"

implementation "org.apache.commons:commons-lang3"
implementation "org.hibernate.javax.persistence:hibernate-jpa-2.1-api"
implementation "com.google.guava:guava"
implementation "org.slf4j:slf4j-api"
implementation "log4j:log4j"

implementation "org.springframework.security:spring-security-web"
implementation "javax.servlet:javax.servlet-api"

compileOnly "com.google.code.findbugs:jsr305"
compileOnly "org.apache.ivy:ivy:2.4.0"
compileOnly("stratum:stratum") {
    transitive = false
}

To this:

compileOnly "org.nrg.xnat:web"
compileOnly "org.springframework.security:spring-security-ldap"
compileOnly "org.slf4j:slf4j-nop"

If you run this:

$ ./gradlew dependencies

You'll see that ecs:ecs:1.4.2 gets pulled in through a number of transitive dependencies.

1
howlger On

org.apache.ecs.ConcreteElement is from the Apache Element Construction Set (ECS) and for example contained in ecs-1.4.2.jar.

To resolve the issue add a dependency to your build.gradle file like the following:

// https://mvnrepository.com/artifact/ecs/ecs
compile group: 'ecs', name: 'ecs', version: '1.4.2'