Bitbucket Jdk版本不匹配问题



我正在Java 1.8版本上开发我的应用程序,由于我的存储库位于bitbucket上,所以它采用Java 11的默认配置。一切都很好,但当我使用Junit Mockito框架编写集成测试时,我在执行管道时遇到了位桶异常。在当地,所有测试都运行良好。

Bitbucket默认选择声纳插件的最新版本,它是3.9,正因为如此,我得到了这个异常

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project xyz: Execution default-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar failed: An API incompatibility was encountered while executing org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar: java.lang.UnsupportedClassVersionError: org/sonar/batch/bootstrapper/EnvironmentInformation has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

我尝试了以下更改,但什么都没发生

1) Changed image: maven:3.6.3-jdk-11 To image: maven:3.6.3-jdk-8 in bitbucket-pipeline.yml file.
2) Added jacoco 0.7.9 version (Java 8 compatible) in pom file
3) Added sonar-maven-plugin version 3.6 (tried to downgrade it to be compatible with Java 8) in pom file

有人能指导缺失的东西和可能出现的问题吗。此外,如果我想更改默认的bitucket docker映像配置,我该怎么做?

我的bitbucket-pipeline.yml文件

image: maven:3.6.3-jdk-11   #image: maven:3.6.3-jdk-8
clone
....
definitions
caches
sonar: ....
steps
...
...
script:
cd impl
mvn -B org.jacoco:jacoco-maven-plugin:prepare-agent verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar

我的集成测试文件

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
@ActiveProfiles("test")
@RunWith(SpringRunner.class)
public class CountryControllerTest{
@Autowired public MockMvc mockMvc;
@Test
public void getCountryListTest() throws Exception {
mockMvc
.perform(MockMvcRequestBuilders.get("/api/countries"))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.data.length()").value(2))
.andExpect(jsonPath("$.data[0].name").value("USA"))
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
}
}

错误仅发生在比特桶管道上,而不发生在本地开发中

[ERROR] getCountryListTest(com.xyz.controller.CountryControllerTest)  Time elapsed: 0.001 s  <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'MyTokenFilter': Unsatisfied dependency expressed through field 'myRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myRepository': Cannot create inner bean '(inner bean)#7675d305' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#12345': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myRepository': Cannot create inner bean '(inner bean)#12345' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#12345': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#12345': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
Caused by: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
Caused by: java.lang.reflect.InvocationTargetException
Caused by: java.lang.NullPointerException

试试Java SE 17。Java SE 8正在慢慢停产。

或者尝试使用GitHub或GitLab。那就行了。

Github中还有一个名为ci circle的免费应用程序。

一旦你安装它就很容易。它是免费的。

它可以在你每次提交时自动构建你的应用程序。

相关内容

最新更新