Current setup of legacy project is: Java 11, Maven 3.6.3, Spring boot 2.1.6. Development is on Windows 10 Pro machines, usual setup, nothing special. When project is built and ran in IntelliJ Idea there were NEVER circular dependencies between Java classes. We noticed this problem a while ago during runtime when deployed in test environment which is just Windows Server 2019 Datacentar machine. No matter if JAR file is run as Windows service or with java -jar command in command prompt. Then we fix code based on error and we continued until next problem. Sometimes problem occurs even on development machine if we build in command prompt with 'mvn clean install'.
What puzzles me is why it never happens in Idea and how to actually setup Idea to happen there as well. I know there is option to detect Cyclic dependency, but architecture is all wrong and we don't have time to start rewriting app now. Eventually we will do - I agree.
Today something even more weird happened. No problem on development machine (Idea or command line). No problems if code is build on test machine with command line. But when code is build as it should be with Azure DevOps circular dependency occurred. I fixed it but I still don't understand why code built OK on Azure DevOps and then when ran on test machine it had runtime error?
Java is same version 11.0.8 (Oracle), except for Azure DevOps 11.0.10 (AdoptOpenJDK). I tried to install AdoptOpenJDK on one dev machine, but still can't reproduce latest error which is happening ONLY if we run jar built on Azure on windows test machine.
UPDATE: In Azure DevOps pipeline, instead of 'ubuntu-latest' I chose 'windows-latest' and now it works (although now I have problem with front end / reactjs build, but that is another topic).
CLARIFICATION: Circular dependency is happening between two, sometimes three classes. As we use Spring Constructor based DI we resolve issues by simply substituting it with field based DI. So if we have ten parameters in Constructor where each represent classes, we remove "problematic" from Constructor and create field based DI for them.
Real problem is that it happens without obvious reasons. For example, today we had new build, just minor changes in code, we changed one IF statement. So NOTHING related to adding or removing DI classes. And this problem occurred. We had at least 15 deployments with zero problems and then this happened.
UPDATE 2: As all build yield no compile time error, and as all executions of JAR built on physical machines (development and test/production) also yield no error, but only JAR build on Azure DevOps during runtime (java -jar filename.jar) I suspected that something might be wrong with cloud build. I've removed this line:
mavenOptions: '-Xmx3072m'
from azure-pipelines.yml
- task: Maven@3
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'package'
and now when we execute jar file, there is no error during runtime.
Error which we had was (I have to retype, cant copy and paste from prod server:
***************************
APPLICATION FAILED TO START
***************************
Description:
The dependencies of some of the beans in the application context form a cycle:
assessmentRuleEngineService defined in URL [jar:file:C:/Project/somewebapp-SNAPSHOT.jar!/BOOT-INF/classes!/some/company/ruleengine/assessment/AssessmentRuleEngineService.class]
???????
| assessmentServiceImpl defined in URL [jar:file:C:/Project/somewebapp-SNAPSHOT.jar!/BOOT-INF/classes!/some/company/services/AssessmentServiceImpl.class]
? ?
| userPermissionService
? ?
| organizationServiceImpl
???????
So to sum up:
- Whey there is never error when ran in Idea and how to make error happen there as well so we notice it before deploy?
- Why sometimes there are absolutely no cyclic dependency errors on development machines but there are on test/prod machines?
- Why sometimes jar built on Azure DevOps has errors while there are no errors neither in development nor test/prod machines.
- Why there is difference with Ubuntu 18.04 build and Windows 2019 build?