When I go to my project structure and right click -> new, I only see new file/folder etc... but no class generation or packages. How do I get IntelliJ to do this? (I have Intellij 14 Ultimate - see image below)
In the Project tool window ( Alt+1 ), right-click the node in which you want to create a new class and select New | Java Class. Alternatively, select the node, press Alt+Insert , and select Java Class.
In the Project window, right-click a Java file or folder, and select New > Java Class. Alternatively, select a Java file or folder in the Project window, or click in a Java file in the Code Editor. Then select File > New > Java Class. The item you select determines the default package for the new class or type.
To create a new class, press ⌘N on MacOS or Alt+Insert on Windows or Linux on the directory in the Project Window, and select “Java class”. When creating a new class, we can type the whole package path, separated by dots, followed by the class name, and IntelliJ IDEA will create the package and the Java file.
Create a new test class manuallyRight-click the test root folder or package in the test root folder in which you want to create a new test and select New | Java Class. Name the new class and press Enter . Press Alt+Insert and select Test Method to generate a new test method for this class.
IntelliJ will offer the option to create new class in the new menu, only if you right click within the part of your project structure, which is marked as Sources root or Test sources root.
In your case, right click the src/main
directory in the project structure view and select Mark directory As/Sources Root. That should fix it.
Also, Gradle expects Java classes to be placed in src/main/java
(and test Java classes in src/test/java
) by default. I think that if you followed this convention, IntelliJ would mark those folders as (Test) Sources Root automatically. So maybe it would be better solution to adjust your project structure according to this convention.
Here is a quote from Gradle guide regarding this issue:
Gradle expects to find your production source code under src/main/java and your test source code under src/test/java
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With