# Gradle compilation issue when running tests

**URL:** https://discuss.gradle.org/t/gradle-compilation-issue-when-running-tests/1750
**Category:** Old Forum Archive
**Created:** [March 22, 2014, 3:47pm UTC](https://discuss.gradle.org/t/gradle-compilation-issue-when-running-tests/1750 "2014-03-22T15:47:00Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![avalanche](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@avalanche](https://discuss.gradle.org/u/avalanche)
#### Post date: [March 22, 2014, 3:47pm UTC](https://discuss.gradle.org/t/gradle-compilation-issue-when-running-tests/1750/1 "2014-03-22T15:47:00Z")

</div>

Hi All,

I have strange issue with gradle. When I run my tests via IDE everything is working I have no errors, no compilation issues. However when I try to run gradlew test I have compilation error:

```gradle
SpringDatabaseConfig.java:34: error: cannot find symbol
  lcemfb.setPackagesToScan("xxx");
        ^
  symbol:
 method setPackagesToScan(String)
  location: variable lcemfb of type LocalContainerEntityManagerFactoryBean
1 error

```

This is part of the class that is causing the issue

```gradle
public class SpringDatabaseConfig {
   @Bean
 public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() {
  LocalContainerEntityManagerFactoryBean lcemfb = new LocalContainerEntityManagerFactoryBean();
  lcemfb.setDataSource(dataSource());
  lcemfb.setPackagesToScan("xxx");// here is compilation error
  lcemfb.setPersistenceUnitName("TestPU");
  HibernateJpaVendorAdapter va = new HibernateJpaVendorAdapter();
  lcemfb.setJpaVendorAdapter(va);
  Properties ps = new Properties();
  ps.put("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
  ps.put("hibernate.hbm2ddl.auto", "create");
  lcemfb.setJpaProperties(ps);
  return lcemfb;
 }

```

I don’t have any idea what can be wrong. This is my environment:

```gradle
Gradle 1.11
------------------------------------------------------------
  Build time:
 2014-02-11 11:34:39 UTC
Build number: none
Revision:
   a831fa866d46cbee94e61a09af15f9dd95987421
  Groovy:
     1.8.6
Ant:
        Apache Ant(TM) version 1.9.2 compiled on July 8 2013
Ivy:
        2.2.0
JVM:
        1.7.0_45 (Oracle Corporation 24.45-b08)
OS:
         Mac OS X 10.9.2 x86_64

```

This is my build.gradle for this project:

```gradle
repositories {
 mavenCentral()
}
  dependencies {
 testCompile 'junit:junit:4.11'
 testCompile 'org.springframework:spring-jpa:2.0.8'
 testCompile 'org.springframework:spring-test:4.0.1.RELEASE'
 testCompile 'hsqldb:hsqldb:1.8.0.10'
 testCompile 'org.mockito:mockito-all:1.8.4'
 testCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
}
+ idea plugin and java

```

Thanks in advance for any tips or suggestions. Best Regards.

---

<div class="post-metadata">

### Author: ![jnizet](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jnizet/32/123_2.png) [@jnizet](https://discuss.gradle.org/u/jnizet)
#### Post date: [March 23, 2014, 5:13pm UTC](https://discuss.gradle.org/t/gradle-compilation-issue-when-running-tests/1750/2 "2014-03-23T17:13:00Z")

</div>

AFAIK, spring-jpa is an obsolete library. You probably want spring-orm:4.0.1-RELEASE: the spring jar containing JPA support for the version 4.0.1 of Spring (the same as the one you use for tests)

---

<div class="post-metadata">

### Author: ![avalanche](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@avalanche](https://discuss.gradle.org/u/avalanche)
#### Post date: [March 24, 2014, 4:09pm UTC](https://discuss.gradle.org/t/gradle-compilation-issue-when-running-tests/1750/3 "2014-03-24T16:09:00Z")

</div>

After changing this dependency indeed it work. Thanks for help. There is though still one thing that I don’t understand. Why IDE was able to compile the code but gradle wasn’t?

Best Regards

---

<div class="post-metadata">

### Author: ![jnizet](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jnizet/32/123_2.png) [@jnizet](https://discuss.gradle.org/u/jnizet)
#### Post date: [March 24, 2014, 4:59pm UTC](https://discuss.gradle.org/t/gradle-compilation-issue-when-running-tests/1750/4 "2014-03-24T16:59:00Z")

</div>

Because the IDE put the correct spring jar file before the incorrect one in the classpath, whereas Gradle put the incorrect one before the correct one.
