1

Cloned Java project from someone else GitHub repo and after opening up a project folder inside InteliJ - it does not show 'RUN' for the main class.

These are options available:
enter image description here

After finding 'main' function in Kotlin - there is still no 'RUN' or green button to run: enter image description here
I noticed that can Mark Directory (for 'src') as 'Resources Root' and that could solve some of the issues but wondering why is this a case and what is the right way to approach to cloned github projects and running them without too much interventions in IntelliJ?

Joe
  • 11,983
  • 31
  • 109
  • 183
  • Please provide the [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). Make sure content roots are configured correctly: https://www.jetbrains.com/help/idea/configuring.-content-roots.html – CrazyCoder Mar 09 '18 at 18:44

4 Answers4

2

Adding this comment for easy access to answer.

Faced similar issue and had to hustle through multiple posts. Finally solved it using these questions - Auto errors detection in IntelliJ IDEA and Configure Kotlin to an existing project in IntelliJ.

TL;DR:

  1. Right click the "src" folder.

  2. Mark directory as Sources Root

  3. Will ask you to configure Java SDK and Kotlin Plugin for the module (Would suggest it on top of source file).

  4. Run the code like charm now.

Anand Mattikopp
  • 332
  • 2
  • 11
2

First option:

Simply choose File -> Invalidate Caches/Restart... and rerun.

Second option:

I've reproduced the same issue after git clone command.

As you can see on the screen below, with no Run option:

enter image description here

And if I right-click the same list, I see:

enter image description here

To solve it, firstly, I've specified SDK in Project Structure, because it wasn't defined by default:

enter image description here

And specified output folder there:

enter image description here

Secondly, I've changed language level option and marked src folder as Source inside Project Structure -> Modules (other folders if you need by requirements):

enter image description here

*On this stage most likely you will see triangles on lines, but still invalid runner.

Lastly, I've added RunManager inside .idea -> workplace.xml file like:

<component name="RunManager">
    <configuration name="Main" type="Application" factoryName="Application" temporary="true">
      <option name="MAIN_CLASS_NAME" value="task01.Main" />
      <module name="project_name_here" />
      <option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
      <RunnerSettings RunnerId="Run" />
      <ConfigurationWrapper RunnerId="Run" />
      <method v="2">
        <option name="Make" enabled="true" />
      </method>
    </configuration>
  </component>

After all these actions, I can use runner again, but be careful with xml file configuration.

To be noticed: this is workaround if you can't find green triangle for main method.

invzbl3
  • 5,872
  • 9
  • 36
  • 76
1

Find the main method and use the green triangle to run it from there. Once you've done that once it will be in your list of configurations in the Run menu.

enter image description here

OldCurmudgeon
  • 64,482
  • 16
  • 119
  • 213
  • I do not see any green triangle to run. It is a Java/Kotlin project and I can see a 'fun main...' but no green triangle anywhere around it nor with right-click out of box.. – Joe Mar 09 '18 at 15:49
  • Added picture to illustrate. – Joe Mar 09 '18 at 15:57
0

I solved this by:

  1. In Intellij IDEA: File -> New -> Project from Existing Sources
  2. Select your file with src folder.
  3. Next select "Project from existing sources" (or Maven/Gradle if you know they are used for your project)
  4. Select Project Name/Location. I left them default.
  5. Overwrite .idea file if exists
  6. Leave source files/libs/modules selections default
  7. Select your SDK Now it should work. Make sure you know whether it is Maven/Gradle or other type of project. It will save your time.
vitaliis
  • 4,082
  • 5
  • 18
  • 40