Enable Partial Compilation in IntelliJ IDEA - java

How do I enable partial compiles in IntelliJ?
The same feature in NetBeans where by one can run a main method in a class without having non-dependecies in the same project be required to also compile.
EDIT:
After performing what CrazyCoder suggested, with some success, now I get ClassNotFoundException when trying to run a file not associated with those that were not compiling. After fixing the non-compiling files, it runs just fine.
I actually made in error in the same non-compiling file to test and it still works.
Could it be a bug?
EDIT:
Followed instructions still not working.

IntelliJ IDEA doesn't welcome working on the project that fails to compile, but there are several options:
use Compile action from the file/folder context menu, disable Build in Run/Debug configuration.
in the Before launch section of the Run/Debug configuration remove Build and add Build, no error check instead. Now start the configuration and it will ignore compilation errors trying to run on whatever classes managed to compile.
You should note that Make will fail on the first error and will not try to proceed further. In this case you should use explicit Compile action. Make also deletes output class files for the sources with errors.
If you want compilation to proceed after errors, you should switch to Eclipse compiler in IntelliJ IDEA Settings | Compiler | Java Compiler. When Eclipse compiler is selected, Proceed on errors option appears and it's enabled by default. With Eclipse compiler, an option to Proceed on errors enabled and Build, no error check in Before launch section you should get the desired behavior.

Navigate to the Build menu at the bottom of your test editor, right-click on the folder that contains error messages that you find irrelevant.
Choose "Exclude from compile".

To make CrazyCoder comment more visible, if you go for the "proceed on errors" behavior you may want to uncheck
Settings | Compiler | Automatically show first error in editor.

I'm working with 2020.2.3 version of IntelliJ.
I've tried all CrazyCoder's suggestions, but nothing works for me.
Eclipse Compiler + Build No-Error-Check
IntelliJ just refuses to Run anything (unit tests, main() methods...) because errors exist in the project.
All I can say is that Eclipse is still working where IntelliJ remains blocked.

Step 1: Setting as follow:
Step2: Build Project Automatically
Step 3: Modify Run configuration
Step 4: close all app console-view tabs in Run View, then run app again Ctrl+Shift+F10

Recompile only selected files:
Select packages or files that needs to be compiled.
Menu → Build → Recompile selected files (⇧ ⌘ F9)
If you need to run or debug, you need to set Do not build before run:
Menu → Run → Edit Configurations...
☑︎ Your target run configuration
Run / Modify options → Java / ☑︎ Do not build before run

Another way of doing this is to set
Use classpath for module field
in Junit configuration tab in your test configurations as your own module. By default it is all_local_extensions.
Attached screenshots.

Related

How to run specific java file without entire project build (Gradle) to happen in IntelliJ? [duplicate]

How do I enable partial compiles in IntelliJ?
The same feature in NetBeans where by one can run a main method in a class without having non-dependecies in the same project be required to also compile.
EDIT:
After performing what CrazyCoder suggested, with some success, now I get ClassNotFoundException when trying to run a file not associated with those that were not compiling. After fixing the non-compiling files, it runs just fine.
I actually made in error in the same non-compiling file to test and it still works.
Could it be a bug?
EDIT:
Followed instructions still not working.
IntelliJ IDEA doesn't welcome working on the project that fails to compile, but there are several options:
use Compile action from the file/folder context menu, disable Build in Run/Debug configuration.
in the Before launch section of the Run/Debug configuration remove Build and add Build, no error check instead. Now start the configuration and it will ignore compilation errors trying to run on whatever classes managed to compile.
You should note that Make will fail on the first error and will not try to proceed further. In this case you should use explicit Compile action. Make also deletes output class files for the sources with errors.
If you want compilation to proceed after errors, you should switch to Eclipse compiler in IntelliJ IDEA Settings | Compiler | Java Compiler. When Eclipse compiler is selected, Proceed on errors option appears and it's enabled by default. With Eclipse compiler, an option to Proceed on errors enabled and Build, no error check in Before launch section you should get the desired behavior.
Navigate to the Build menu at the bottom of your test editor, right-click on the folder that contains error messages that you find irrelevant.
Choose "Exclude from compile".
To make CrazyCoder comment more visible, if you go for the "proceed on errors" behavior you may want to uncheck
Settings | Compiler | Automatically show first error in editor.
I'm working with 2020.2.3 version of IntelliJ.
I've tried all CrazyCoder's suggestions, but nothing works for me.
Eclipse Compiler + Build No-Error-Check
IntelliJ just refuses to Run anything (unit tests, main() methods...) because errors exist in the project.
All I can say is that Eclipse is still working where IntelliJ remains blocked.
Step 1: Setting as follow:
Step2: Build Project Automatically
Step 3: Modify Run configuration
Step 4: close all app console-view tabs in Run View, then run app again Ctrl+Shift+F10
Recompile only selected files:
Select packages or files that needs to be compiled.
Menu → Build → Recompile selected files (⇧ ⌘ F9)
If you need to run or debug, you need to set Do not build before run:
Menu → Run → Edit Configurations...
☑︎ Your target run configuration
Run / Modify options → Java / ☑︎ Do not build before run
Another way of doing this is to set
Use classpath for module field
in Junit configuration tab in your test configurations as your own module. By default it is all_local_extensions.
Attached screenshots.

How to get a compile available eclipse?

I'm doing a project and I need to make a small change to Eclipse (I need to turn off the sourcelookup function because it's slow).
But I can't find the source codes which are available to compile.I always get errors from those getting on the git.
So could you help me getting the source codes of Eclipse and compiling it? I'm new to Ant and Mvn.
Thanks!
Assuming your statement - I need to turn off the sourcelookup function because it's slow - means you do not want to compile everytime the source changes, I am answering this below.
If you want to turn off automatic build in Eclipse from the Project Menu uncheck Build Automatically menu item Project -> Build Automatically
This will stop auto building of your project every time you save something in your project. But be aware that you will not get your changes compiled automatically and will need to do a manual build.

IntelliJ. Debug a program even if it does not compile

I have a Java project in IntelliJ that compiles, and now I am slowly changing.
Is there a way to ask IntelliJ to run the project, even if some parts of the code still do not compile? If so, how?
Why I would need this, you ask? see this ticket:
IDEA-61945 Run and Debug commands should ignore compile errors not related to the main being run.
http://youtrack.jetbrains.net/issue/IDEA-61945?query=it#tab=Comments
Please, do not answer this post questioning whether I should or I should not need to run a project even if it does not compile. please.
If not possible in IntelliJ, is it possible in maven? How?
In Intellij 12 you also have the following option (which personally I find the best one):
Go to Edit configuration of your launcher
Go to the before launch section
If 'Make' is in the list: remove it
Add 'Make, no error check'
Now, when you run, a make will still be done automatically but the run will continue even if the are compilation errors.
Regarding the above debate; I think it makes perfect sense to be able to run a part of the code that does compile even if another part of the code does not not; e.g. if that other part of the code belongs to a module that is in your project but not involved when running.
I ran into this exact same problem at work today. Before now, I probably would have been quick to jump on the bandwagon of, "Why would you ever want to do that?" Turns out that Eclipse lets you do exactly this, and if you start working concurrently with other developers who depend on this feature (which is to say, check in code that doesn't compile), it's handy to be able to do the same in IDEA!
And lucky for us IDEA users, you can. Follow these instructions from the FAQ for Eclipse Users, and you're good to go:
To be able to run code with errors, you can select the Eclipse
compiler in Settings dialog, Compiler, Java Compiler and add the
-proceedOnError option to the Additional command line parameters for the compiler.
The only thing that's lame is that it's not quite as seamless as in Eclipse. First, you'll have to untick the option to Make before run because IDEA won't run if make fails. Then, you'll have to remember to build before running. With those caveats, though, you should be able to accomplish what you're after.
Stijn Geukens's answer is correct, but it can be improved.
In Intellij Idea version 12 instead of removing the "Make" rule it can be replaced with "Make, no error check". This way project will be rebuilt (compiler will atempt to do it), but it will run the program independently of compile outcome.
If you want to debug just one part, then you can create a unit test around that. If you do not use the class that does not compile, then you can still debug the unit test related code.
When there are compilation errors, you can exclude specific files from compilation.
Go to the Messages window (if it is not visible: View -> Tool Windows
-> Messages)
Right click the problem file
Exclude from compile
At least in Intellij 12 you can achieve this.
First try to compile the project, including the broken class(es).
Then in the Messages view, containing all the compile errors:
Right-click the class you want to exclude
Click 'exclude from compile'
See this question on how to reinclude afterwards.
For Intellij 2017.3.1 my configuration is like this:
Use the Eclipse Compiler: Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler -> Use compiler: Eclipse
Select "Proceed on errors"
Edit your desired configuration defaults (I use this for JUnit) before launch to Build, no error check: Check this screenshot
Additional step in order for Intellij not to open the classes with errors when you run your configuration. Un-select Automatically show first error in editor in Settings -> Build, Execution, Deployment -> Compiler
PS: This configuration is not perfect for all usages. It only works when you are fixing unit tests that were failing because of your changes in implementation code. When you go back to implementing features it is more useful to disable this feature since it will let you run you implementation code with errors and it will not jump to compilation errors. You need to go back and forth with changing the Eclipse compiler with the Javac one for best results.
Wow, it's been a while since I've been in IntelliJ and I miss it dearly! From my recollection you should be able to right click the main method in a module and run it directly so long as the remainder of the files in the module compile. I don't think it matters that a second module in the same project has errors. Is that not working for you?
updating for version 2017 - 2.5 community as menu options are slightly different
Navigate to:
Run>Edit Configurations
near the bottom of the Run/debug config window look for
"before launch: Activate tool window "
the field below this heading lists your current build config settings.
Use the + and - symbols in order to add and remove build preferences.
Once completed
Select apply then Okay
Thats it!
I don't think its possible at all. How you can run something that doesn't compile? That would be like driving a car that isn't put together. You could comment out the files that don't compile, so that the project compiles....
Edit -- or you can have Intellij not count the file as source by
Right Click on your project -> open module settings -> select your module -> select the file -> excluded

Why is my Eclipse launch configuration not being added to the Run or Debug configurations list?

I have a .launch file which I can run by context menu (Run As...), but it is not being added to the list of Debug or Run configurations like it should. Why not?
There is something wrong with the launch config. Possibly a project is being referenced which is closed (that's what it was for me)...
So the launch may work (in my case this was because the project wasn't actually required) but any issues like this will cause it not to be added to the list of launches. To figure out what the cause is, you can
Try running the launch file
In the "Debug" view (not perspective, but view i.e. tab), right click the launch and select "Edit <launch name>...". This properties window will show you any errors. Once those are fixed, it will add the launch to the list of run configs.
You can also uncheck the options "Filter configurations in closed project" and "Filter configurations in deleted or missing projects". This should do the trick.
Try to remove filter from filtering preferences
This may be any help at all but I assumed that when importing a project it would be added to general list of "Run Configurations", but as I added a java run config it is added to "Java Application" parent node in Eclipse "Run Configurations".
For me, this happens due to copy the same project and giving the other name so my project name is not showing in the launch configuration (for not showing in the launch configuration there could be some other reasons.)
Fix:
Right-click on the project select Coverage as after this will get two
option java application and configuration.
select java application it will run the project and create the
coverage.
Other option is just run the Application it will create the coverage.

How do I run JUnit from NetBeans?

I've been trying to understand how to start writing and running JUnit tests.
When I'm reading this article:
http://junit.sourceforge.net/doc/testinfected/testing.htm
I get the the middle of the page and they write, "JUnit comes with a graphical interface to run tests. Type the name of your test class in the field at the top of the window. Press the Run button."
I don't know how to launch this program. I don't even know which package it is in, or how you run a library class from an IDE.
Being stuck, I tried this NetBeans tutorial:
http://www.netbeans.org/kb/docs/java/junit-intro.html
It seemed to be going OK, but then I noticed that the menu options for this tutorial for testing a Java Class Library are different from those for a regular Java application, or for a Java Web App. So the instructions in this tutorial don't apply generally.
I'm using NetBeans 6.7, and I've imported JUnit 4.5 into the libraries folder. What would be the normal way to run JUnit, after having written the tests?
The JUnit FAQ describes the process from the Console, and I'm willing to do that if that is what is typical, but given all that I can do inside netbeans, it seems hard to believe that there isn't an easier way.
Thanks much.
EDIT: If I right-click on the project and select "Test" the output is:
init:
deps-jar:
compile:
compile-test:
test-report:
test:
BUILD SUCCESSFUL (total time: 0 seconds)
This doesn't strike me as the desired output of a test, especially since this doesn't change whether the test condition is true or not.
Any ideas?
One way is to right click on your project in the Projects pane and select "Tests". That will run the JUnit tests. You can also right click on the test file and select "Run Test" and that single file will be ran. The keyboard shortcuts depends on how you have your keymapping set, but you'll see them in the context menus.
You can also have NetBeans autogenerate tests for you by right clicking your source file and then "Tools > Create JUnit Tests".
Re-importing does not appear to be necessary. I had the same issue (imported project, right clicking did not bring up any JUnit test options). I took these steps, which resolved it, using NetBeans 6.8:
Add a folder called "tests" to your project.
Right-click your project and select Properties.
Select Sources.
Under Test Package Folders, click the Add Folder button, and select the "tests" folder.
Right clicking a file + Tools > Create JUnit Tests.
Once a test is created, right-clicking a file + Test File runs the test.
All the above answers are correct, but if you are using in mac little change needed.
Step 1 Write your junit class.
Step 2 Right click on the class ->Tools-> Create/Updates Tests-> Select framework as Junit-> click ok.
Step 3 Right click on the file again ->Test File.
Now it will run as junit, will show the Test Result.
Even though I've accepted an answer, I thought I should mention my difficulty, as someone else may encounter it.
When importing a project from existing sources into NetBeans, if you do not specify a folder for test packages, then NetBeans will not offer the JUnit options on the tools menu.
The only solution I found was to re-import the project. While primitive, it worked.
I had the same issue after imported a eclipse project into NetBeans.
To resolve it, I followed the above steps outlined by alangalloway, but instead of
creating a new folder, I just pointed to the imported test folder.
Maybe in future release, NetBeans can automatically recognize imported test cases.
Thanks.
Had a similar issue. In Netbeans 7.0.1, what worked for me was to locate the project.xml file (i.e. {project}/nbproject/project.xml) and change:
<test-roots/>
to:
<test-roots>
<root id="src.dir"/>
</test-roots>
(in my case the test files are in the same dir as the source dir)

Categories

Resources