inspect.sh in CI without .iml/modules.xml files - Project contains no modules

Answered

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?

0
14 comments

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/
0

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:

jenkins@dev:~/workspace/services-pull-requests_PR-26$ /opt/intellij-idea-community/bin/inspect.sh . .idea/inspectionProfiles/Project_Default.xml target -v2
Starting up IntelliJ IDEA 2021.2.2 (build IC-212.5284.40) ...done.
Opening project...
Checking project configuration...

Loading components...
2021-10-06 17:24:27,333 [ 1681] WARN - l.NotificationGroupManagerImpl - Notification group CodeWithMe is already registered (group=com.intellij.notification.NotificationGroup@50705377). Plugin descriptor: PluginDescriptor(name=Code With Me, id=com.jetbrains.codeWithMe, descriptorPath=plugin.xml, path=/opt/intellij-idea-community/plugins/cwm-plugin, version=212.5284.40, package=null)
Preparing workspace...




Reopening files...







Scanning files to index...
Scanning files to index...


2021-10-06 17:24:30,007 [ 4355] WARN - g.jetbrains.kotlin.idea.script - [KOTLIN_SCRIPTING] extension gradle.kts file type [UNKNOWN] is not registered as Kotlin
2021-10-06 17:24:30,007 [ 4355] WARN - g.jetbrains.kotlin.idea.script - [KOTLIN_SCRIPTING] extension space.kts file type [UNKNOWN] is not registered as Kotlin
2021-10-06 17:24:30,007 [ 4355] WARN - g.jetbrains.kotlin.idea.script - [KOTLIN_SCRIPTING] extension main.kts file type [UNKNOWN] is not registered as Kotlin
2021-10-06 17:24:30,008 [ 4356] WARN - g.jetbrains.kotlin.idea.script - [KOTLIN_SCRIPTING] extensions [gradle.kts, space.kts, main.kts] is about to be registered as Kotlin
done.
Initializing project...Loaded profile 'Project Default' from file '.idea/inspectionProfiles/Project_Default.xml'
done.
Inspecting with profile 'Project Default'

This project contains no modules. Inspection cannot proceed.

Scanning scope ...


Done.
0

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.

 
 
0

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:

Please, specify sdk 'null' for module 'ModuleA'

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?

0

> 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:

Please, specify sdk 'null' for module 'ModuleA'

 

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.

 
0

This does not work. Even If I only create an empty .idea folder in the Directory then I will get the

This project contains no modules. Inspection cannot proceed.

error again. So no way to keep the misc.xml file.

Input/output:

jenkins@dev:~/workspace/services-pull-requests_PR-26$ mkdir .idea
jenkins@dev:~/workspace/services-pull-requests_PR-26$ /opt/intellij-idea-community/bin/inspect.sh /var/lib/jenkins/workspace/services-pull-requests_PR-26 /var/lib/jenkins/workspace/services-pull-requests_PR-26/Project_Default.xml /var/lib/jenkins/workspace/services-pull-requests_PR-26/target/report -v2
Starting up IntelliJ IDEA 2021.2.2 (build IC-212.5284.40) ...done.
Opening project...
Checking project configuration...

Loading components...
2021-10-19 14:38:23,592 [ 1733] WARN - l.NotificationGroupManagerImpl - Notification group CodeWithMe is already registered (group=com.intellij.notification.NotificationGroup@113b3fdc). Plugin descriptor: PluginDescriptor(name=Code With Me, id=com.jetbrains.codeWithMe, descriptorPath=plugin.xml, path=/opt/intellij-idea-community/plugins/cwm-plugin, version=212.5284.40, package=null)
Preparing workspace...




Reopening files...







Scanning files to index...
Scanning files to index...


2021-10-19 14:38:28,914 [ 7055] WARN - g.jetbrains.kotlin.idea.script - [KOTLIN_SCRIPTING] extension gradle.kts file type [UNKNOWN] is not registered as Kotlin
2021-10-19 14:38:28,914 [ 7055] WARN - g.jetbrains.kotlin.idea.script - [KOTLIN_SCRIPTING] extension space.kts file type [UNKNOWN] is not registered as Kotlin
2021-10-19 14:38:28,915 [ 7056] WARN - g.jetbrains.kotlin.idea.script - [KOTLIN_SCRIPTING] extension main.kts file type [UNKNOWN] is not registered as Kotlin
2021-10-19 14:38:28,915 [ 7056] WARN - g.jetbrains.kotlin.idea.script - [KOTLIN_SCRIPTING] extensions [gradle.kts, space.kts, main.kts] is about to be registered as Kotlin
done.
Initializing project...Loaded profile 'Project Default' from file '/var/lib/jenkins/workspace/services-pull-requests_PR-26/Project_Default.xml'
done.
Inspecting with profile 'Project Default'

This project contains no modules. Inspection cannot proceed.

Scanning scope ...


Done.

 

 

0

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.

0

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

Method is never used.

Are there any other plugin files/configurations I have to be aware of?

 

0

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 

0

Locally and on my Jenkins:

IntelliJ IDEA 2021.2.3 (build IC-212.5457.46)

But I am quite confused now since it seems that different profiles are used.

On my machine:

# Removing the .idea folder to reproduce the conditions on my Jenkins but moved the dir to .idea-bak to retain the inspection Profile
rm -r .idea
./inspect.sh /home/lubi/workspace/services/pom.xml /home/lubi/workspace/services/.idea-bak/inspectionProfiles/Project_Default.xml target/inspections -v2

# Note that 46 files are created by the inspection
lubi@inferno  ~/target/inspections  ls -1 | wc -l
46

# Sanity Check, Inspection Profile exists
lubi@inferno  ~/target/inspections  stat ~/workspace/services/.idea-bak/inspectionProfiles/Project_Default.xml
File: /home/lubi/workspace/services/.idea-bak/inspectionProfiles/Project_Default.xml
Size: 2226 Blocks: 8 IO Block: 4096 regular file
Device: 10301h/66305d Inode: 30016103 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/ lubi) Gid: ( 1002/ lubi)
Access: 2021-10-25 09:19:40.914719447 +0200
Modify: 2021-10-21 10:50:27.433377737 +0200
Change: 2021-10-21 10:50:27.433377737 +0200
Birth: -
lubi@inferno  ~/target/inspections  wc ~/workspace/services/.idea-bak/inspectionProfiles/Project_Default.xml
30 124 2226 /home/lubi/workspace/services/.idea-bak/inspectionProfiles/Project_Default.xml

On my Jenkins:

# Copy Inspection profile 
cp ${env.WORKSPACE}/.idea/inspectionProfiles/Project_Default.xml \
${env.WORKSPACE}/Project_Default.xml

# Remove .idea dir
rm -rf ${env.WORKSPACE}/.idea

# Execute inspection
/var/lib/jenkins/idea-IC-212.5457.46/bin/inspect.sh ${env.WORKSPACE}/pom.xml \
${env.WORKSPACE}/Project_Default.xml \
${env.WORKSPACE}/target/idea_inspections -v2
# Only 33 Files are created, but some files like the unused.xml are much bigger than on my local machine
jenkins@dev:~/workspace/services-pull-requests_PR-26/target/idea_inspections$ ls -1 | wc -l
33

# Sanity Check, Inspection Profile exists and is the same as on my machine
jenkins@dev:~/workspace/services-pull-requests_PR-26$ stat Project_Default.xml
File: Project_Default.xml
Size: 2226 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 1036279 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 111/ jenkins) Gid: ( 116/ jenkins)
Access: 2021-10-25 10:32:38.292535730 +0200
Modify: 2021-10-25 10:32:27.196535730 +0200
Change: 2021-10-25 10:32:27.196535730 +0200
Birth: -
jenkins@dev:~/workspace/services-pull-requests_PR-26$ wc Project_Default.xml
30 124 2226 Project_Default.xml

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!

0

Great, thank you for confirming it works now👍

0

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?

0

Yes, it's by design that inspect and duplocate commands do not require a license in headless mode.

0

Great news for me, Thank you!

0

Please sign in to leave a comment.