0

I have this relatively strange maven project that I work on under intellij, where most submodules are java, but one module contains shell and python script (maven packages those with the maven-assembly-plugin). I manage to configure maven to execute python unitest when executing mvn test and it works when executing it on git-bash. But it doesn't work in intellij when clicking on lifecycle>test in the maven tool window.

The problem seems to be that it executes it in a powershell. We develop under windows, but the project is deployed on linux, so the shell and python scripts are expected to work on linux. I found configuration in intellij to use git-bash in the terminal tool of intellij (for example here), but nothing to use it (or another linux-like shell) to execute maven test.

=> Is there any such configuration?

Note: I am using intellij community edition 2021.3.2. I could probably get a new CE or an ultimate edition if that solves my issue (but I prefere to avoid changing/updating if not necessary)

Juh_
  • 14,628
  • 8
  • 59
  • 92
  • Why having a python script/shell part in your java app? Furthermore why using an old version of IntelliJ ... in the mean time we are at 2023.1.3 .. (that will not solve the issue here)... and no ultimate edition is not related here.. – khmarbaise Jun 27 '23 at 12:07
  • The main reason for having python&shell script in the java project is... that it was setup like that when I arrived :) Now, it is also practical because those are part of the same functional application, and thus are designed and deployed together – Juh_ Jun 27 '23 at 12:32
  • Having an old intellij is just the way it is. I installed it at some point and did not bother updating it. I am quite tired of always having to update everything, especially if I don't get anything useful out of it – Juh_ Jun 27 '23 at 12:34
  • Getting nothing useful out of it? Ok.. You should look the update release notes or look the youtube videoas about the news ...; Apart from that that is was setup like that ... does not help here... furthermore executing tests is simply being done by using `mvn test`... if there are test which use shell etc. you have to improve the test that they are able to handle the differences for windows vs. linux but that sounds wrong because your target is linux ...That brings me to the most important part.. write the code of the scripts in Java that would work on Windows etc. – khmarbaise Jun 27 '23 at 12:46
  • In principle I agree, but first this is not my choice to make (I actually try to push to replace at least bash by python code), and also some process actually needs to call shell tools developped externally. Cannot do much about it. Well, we are off topics anyway – Juh_ Jun 27 '23 at 14:54
  • 1
    Currently it's not possible to set terminal used for execution. Feel free to create feature request on YouTrack: https://youtrack.jetbrains.com/issues/IDEA – y.bedrov Jun 28 '23 at 12:41
  • done: https://youtrack.jetbrains.com/issue/IDEA-323871 – Juh_ Jun 28 '23 at 13:03

1 Answers1

0

This is not an exact answer to my question, but to share the solution I setup for my specific problem of executing python test through maven:

First, I use the exec-maven-plugin for maven to exec python unitest in the test step. However, it works whan called from git-bash (and probably any linux shell) with python intalled, but as explained in my question above, it fails when executed though intellij because it uses a windows shell.

So, what can be done is to use as sh.bat file to call the python unitest command with a unix shell and put "sh" in the 'executable' part of maven exec plugin configuration: in unix, it call the 'sh' command, and on windows system it calls the sh.bat file

in the pom

 <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
      <execution>
        <id>run-python-test</id>
        <phase>test</phase>
        <goals>
          <goal>exec</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <executable>sh</executable>
      <arguments>
        <argument>-c</argument>
        <argument>python -m unittest discover src/test/</argument>
      </arguments>
    </configuration>
  </plugin>

And create a sh.bat file with something like (here I call sh.exe from a git install on windows)

"C:\Program Files\Git\bin\sh.exe" %*

Notes:

Juh_
  • 14,628
  • 8
  • 59
  • 92