Cannot resolve symbol within a Gradle script but resolving within source code
I am developing a gradle build script and I am trying to use an external library that I created.
I uploaded the library to a local repository both the jar and sources jar. Then I tried to use it within a gradle script, using the buildscript statement to define the dependency
buildscript {
repositories {
maven {
name = 'repoLocal'
url = "file://D:/Workspace/mvn_repo"
}
}
dependencies {
classpath 'it.zebco.alm:almproperties:1.3.0'
}
}
Then within the build.gradle script I try to use the library classes
import it.zebco.alm.AlmProperties
AlmProperties ap = new AlmProperties()
which always gets me "Cannot resolve symbol" for AlmProperties references within the same script. If I run "gradle -b build.gradle", execution ends without errors. By the way, if I copy the AlmProperties source code to a buildSrc directory, Intellij Idea resolves the class correctly.
Moreover, if I specify
repositories {
jcenter()
maven {
name = 'repoLocal'
url = "file://D:/Workspace/mvn_repo"
}
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.12'
compile 'it.zebco.alm:almproperties:1.3.0'
}
and I define a dummy.groovy file containing
package dummy
import it.zebco.alm.AlmProperties
AlmProperties ap = new AlmProperties()
AlmProperties class is resolved correctly.
Standard suggestions (restart/resync/reimport the project) don't work.
Any other suggestions ?
Regards
Evelino Bomitali
Please sign in to leave a comment.
Hello Evelino,
Does you dependency shown in "Project Structure | Modules - Dependencies"?
Does it help if you change "classpath" to "compile" here:
Eventually I managed to solve the issue.
Fact is that I wrote
plugins {
id 'groovy'
id 'idea'
}
buildscript {
repositories {
maven {
name = 'almRepoLocal'
url = "file://D:/Workspace/IKAN-PHASE/mvn_repo"
}
}
dependencies {
classpath 'it.zebco.alm:almproperties:1.3.0'
}
}
while writing
buildscript {
repositories {
maven {
name = 'almRepoLocal'
url = "file://D:/Workspace/IKAN-PHASE/mvn_repo"
}
}
dependencies {
classpath 'it.zebco.alm:almproperties:1.3.0'
}
}
plugins {
id 'groovy'
id 'idea'
}
that is plugins statement after buildscript, allow Intellj Idea to resolve correctly the AlmProperties class.
Does moving "plugins" sections back restore error highlighting?