I don't know why but my spring boot test succeed in eclipse when running it as junit, but then fail when I execute the command:
gradle clean build
Here is my build.gradle:
buildscript {
ext {
springBootVersion = '1.5.8.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
sourceCompatibility = 1.8
targetCompatibility = 1.8
jar {
baseName = rootProject.name
version = project.version
}
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework:spring-jdbc')
compile('mysql:mysql-connector-java')
compile('javax.validation:validation-api')
compile('org.hibernate:hibernate-core:5.2.2.Final')
compile('org.hibernate:hibernate-tools:5.2.0.Final')
testCompile('com.h2database:h2:1.4.196')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.security:spring-security-test')
}
All my test fails once I run the gradle command, for various reasons, mainly not being able to create beans and autowire them to the test classes.
Here is a test example:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
@DataJpaTest
@ActiveProfiles("test")
public class IEmployeeRepositoryTest {
@Autowired
private TestEntityManager entityManager;
@Autowired
private IEmployeeRepository employeRepository;
And this is the reason why the build/test fails:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory'
defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is
java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/Properties;
I appreciate all the help I can get, I've been stuck on this for hours.
UPDATE This is the output of my gradle dependencies: Image to gradle dependencies
I should also mention that project structure is this:
src
---main
-----java
-----resources
------application.yml
------schema.sql
---test
-----java
-----resources
------application-test.yml
------schema-test.sql