I have a Spring Component DummyStorageRepository
and interface StorageRepository
written in Groovy
class DummyStorageRepository implements StorageRepository {...
}
Now in my Application.java which is also a spring boot starter config I have
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application implements AsyncConfigurer {
...
@Bean
public StorageRepository storageRepository() {
return new DummyStorageRepository();
}
My Gradle.buid file is plain vanilla.
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.1.8.RELEASE'
classpath 'org.springframework:springloaded:1.2.1.RELEASE'
}
}
apply plugin: 'groovy'
apply plugin: 'spring-boot'
apply plugin: 'project-report'
apply plugin: 'eclipse'
apply plugin: 'idea'
targetCompatibility = 1.8
sourceCompatibility = 1.8
jar {
baseName = 'service'
version = '0.0.1'
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.7:indy'
compile 'org.springframework.boot:spring-boot-starter-actuator:1.1.8.RELEASE'
compile('org.springframework.boot:spring-boot-starter-web:1.1.8.RELEASE')
}
and my file structure is
src/main/groovy/com/app/repository/DummyStorageRepository.groovy, StorageRepository.groovy
src/main/java/com/app/Application.java
src/main/resources/...
This is the error
/app/Application.java:103: error: cannot find symbol
public StorageRepository storageRepository() {
^
symbol: class StorageRepository
location: class Application
If I convert Application.java to Application.groovy and move it to the groovy tree everything is compiled as expected. The same applies if I convert DummyStorageRepository.groovy and StorageRepository.groovy to java and move it into the java tree. I am on gradle 2.1 if it of any matter.
Why to I get "cannot find symbol" error wehen referencing groovy from java?
Update:
I added manually a source set to my gradle.build, just to see what paths are scanned but the result stays the same.
sourceSets {
main {
groovy {
srcDirs = ['src/main/groovy']
}
java {
srcDirs = ['src/main/java']
}
}
test {
groovy {
srcDirs = ['src/test/groovy','src/test/java']
}
java {
srcDirs = ['src/test/java']
}
}
}