inspect.sh in CI without .iml/modules.xml files - Project contains no modules
Hi,
I am currently stuck with getting the IntelliJ inspect to work within my Jenkins Pipeline. I tested everything with the modules.xml and .iml files committed in my multi module maven project and the inspection works but I don't want these files to be in git since they change quite often.
This project contains no modules is the error message I stuck with. I also stumbled upon this ancient maven plugin but it also does not work for me https://maven.apache.org/plugins/maven-idea-plugin/
I tried to generate these files by opening and importing the Project with IntelliJ, but since this is on my Jenkins Server I can't get IntelliJ to start and import a project without GUI.
Is there any way I can generate these files in a headless mode? Is this maybe possible with a custom plugin?
Please sign in to leave a comment.
Could you add more information about the project configuration files that exist under .idea directory?
For me it is working fine: in a Maven-based project I have the Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Maven | Importing | Store generated project files externally option enabled, which means that IDE generates the .idea/modules.xml and module's .iml files outside of the .idea project configuration directory (in the IDE system directory). I ran the inspections using command line:
inspect.sh . .idea/inspectionProfiles/profiles_settings.xml InspectionResults -v2 -d src/The Project is a Maven multi module Project. So I have a "Services" Project, which contains Module A, Module B, Module C. Each with a pom.xml that is referencing a parent pom.xml in the "Services" root dir.
The problem is that because I don't want to commit the .idea/modules.xml and each Modules (A,B,C and the Services) .iml file to version control, these files are missing on my Jenkins builds Server. To test this, clone a repository to a directory without ever opening it with IntelliJ and the try running the inspect.sh.
The .idea files I have committed into version control are: inspectionProfiles/, encodins.xml, misc.xml, vcs.xml, sqldialects.xml. All other files in .idea are listed in my .gitignore
Exact error:
For Maven and Gradle based projects it's supposed to work if you point to the pom.xml/build.gradle when you point to the project. Corresponding importers should open the project then.
It doesn't matter if I use the $ProjectDir or $ProjectDir/pom.xml as path, but I found out that if I delete the .idea folder on my Jenkins then the inspect will run and find the modules. There is now another error though:
So now I know that I have to delete the .idea folder before I can run the inspection, but I don't know how to fix this error, since I can't keep the misc.xml, which contains the sdk. At least the Inspection will return result, but there are now a few false positives due to the undefined sdk.
Is there any other way to specify the sdk for a Project?
> if I delete the .idea folder on my Jenkins then the inspect will run and find the modules.
If there is already existing .idea Including the modules.xml file) directory - the command line tries to open it as an existing (configured earlier) project and does not open it as a new Maven project. If there are not project configuration files related to modules, then IDE first imports it as Maven project and creates a project, then runs the inspections.
>There is now another error though:
Code inspections (be it a command line inspections or inspections run from IDE) rely on a properly defined project SDK. There should be no need to delete the misc.xml file. Please remove modules.xml and .iml files.
This does not work. Even If I only create an empty .idea folder in the Directory then I will get the
error again. So no way to keep the misc.xml file.
Input/output:
Do you have any SDK's configured for the IDE instance that runs inspections? You can see them in File | Project Structure | SDKs dialog. This information is stored in IDE config\options\jdk.table.xml file.
Seems that the JDKs are not configured there or there is no compatible JDK.
I placed a jdk.table.xml file and the inspection runs without error. I still got one Problem now. The Inspection on Jenkins reports 1396 Issues, but the Inspection in my Intellij on my local Pc via Analyze -> Inspect Code... -> whole project reports only 1083 Issues. Any Idea why there are so much more false positives on my Jenkins?
For example I am using Spring and in one of my configuration classes all the @Bean annotated Methods are flagged as
Are there any other plugin files/configurations I have to be aware of?
Hello Lukas,
Are the same IntelliJ IDEA versions used when you run the inspections on server and locally? If yes, are the same inspections xml configs used? Thank you
Locally and on my Jenkins:
But I am quite confused now since it seems that different profiles are used.
On my machine:
On my Jenkins:
Any Idea what's happening here?
EDIT:
I just realized that there is one difference, one is the community edition and another is the ultimate edition. I think Ultimate supports Spring (@Bean) and thus the inspection results differ. Does that mean that I need the Ultimate Edition for CI?
EDIT2:
I tested it with the ultimate edition and everything works now as expected with the inspection! Thanks for help and fast responses!
Great, thank you for confirming it works now👍
Follow Up Question.
What about the license for the IntelliJ Ultimate on the Jenkins? Is it intended that I can use the inspect.sh without logging in/providing an account?
Yes, it's by design that inspect and duplocate commands do not require a license in headless mode.
Great news for me, Thank you!