Can't run Gradle Tasks on project - java

I'm trying to run a Gradle Task by double clicking it on Eclipse, but the task is greyed out and says "Cannot run tasks for included builds" if I right click it as you can see in the image below:
What's that supposed to mean? Suddenly I can't run tasks for no apparent reason when I was able a few hours ago.
My project is Liferay based. I'm under JDK 1.8 and Windows 10.
I tried restarting Eclipse, cleaning project, deleting .gradle folder, changing Gradle version to 4.10 and refreshing tasks but nothing changes.

Please consider the following (It works fine in my case):
Delete the project on eclipse (just check delete nested projects), do not delete the project on the disk
Go the the project on the disk, find and delete all .project files
Re-Import Liferay workspace on eclipse (File > Import > Liferay Workspace Project) and select your project folder
That did the trick ! Gradle tasks are now refreshed in green.

Posting this in case it helps anyone. For me, this problem arose when I added a new Java project and manually converted it to gradle and then added it as a sub-project.
Doing so changed the following line in /.settings/org.eclipse.buildship.core.prefs from this:
connection.project.dir=
to this:
connection.project.dir=mynewproject
Once I changed that line back, I could run all sub-project tasks again.

My project was set up as a Gradle multi-project. I found that the build tasks for the parent and nested projects were greyed out. The fix was to remove the Eclipse Gradle Project Nature ( Project Natures -> Gradle Project Nature) project nature on the parent project, delete the .gradle folder of the parent project and then add the Gradle Project Nature again via Eclipse.

I think I found a solution, in case someone's having the same problem:
Copy project folder into another place
Delete project on Eclipse (check "Delete project contents on disk")
Delete .gradle folder inside the project folder
File > Import > Existing Gradle Project
Look for the project folder
Now you should be able to run Gradle Tasks again.
I hope this helps ;)

Related

Problems with IntelliJ at cloning repo from github

I am new to github. I tried to clone a repo and then pull the files on my computer. All the other team members did the same thing and it worked for them. When i open the project with Intellij all the .java files look like this:
files
It also says that my SDK isn't set.
I tried to set my SDK, and also i tried to set the java directory as 'sources root' because someone said that is a problem with the project structure.
These problems disappeared but then IntelliJ didn't recognize that my project is a maven project so i had to add manually the file pom.xml and refresh maven.
Then this problem disappeared but i had another:
"Cannot start compilation: the output path is not specified for module 'cmsiss'.
Specify the output path in Configure Project."
I tried to set it from project structure but now I have this error:output error
Please help.
Open maven project using pom.xml file. File->Open->pom.xml
Sources should be pointed to project root, not java directory.
Give these a try.
The usual steps that I follow to open the project:
git clone <github clone url>
Open the project in intelli J using
File<Open
and browse to open the root of the project.
This should work fine but if it does not, a few more things you can try:
Try making the project root as a maven module
You can open the Project Structure to make sure you have Java SDK set up properly. It should show the java version you are using there.
Worst case, that is if nothing else works and if the project is not too big, just create a new maven project and make sure it runs, then add all the project files.
I pulled the project again and started from zero. I specified the SDK and then I opened the Maven project window and added a maven project (selected the pom.xml file) and refreshed it. Maven did it's job and created the project structure and all the stuff I've tried to do manually and finally worked!

build error after importing maven projects

I cloned one of the open source git repositories and was trying to import it as maven project in eclipse. After I imported everything as a maven project, whole package is getting messed up. See the below error:
How can I fix this issue so that I can build it on my local box? I cloned the same git repository locally on my desktop.
I am using eclipse version:
Eclipse IDE for Java Developers
Version: Luna Service Release 1a (4.4.1)
Build id: 20150109-0600
Steps I have tried already:
I have already tried maven->update project.
I have also tried removing and adding it again.
I tried mvn clean install both on command line and eclipse, they are successful as well.
Can anyone help me with this? If needed, you can also clone it and try importing it to see whether it works for you or not.
The root of your problem is that the build section of the pom.xml for that project specifies:
<sourceDirectory>./src</sourceDirectory>
Eclipse uses the sourceDirectory tag to tell it where the root of the main sources are. If you change that to ./src/main/java, then right-click on the project > Maven > Update Project... and click Ok (I had to do this twice) it will fix the Eclipse classpath so Eclipse can build the project. You can then revert the pom back to the head revision and so long as you don't run Update Project again it should continue to build.
I'm unclear on why that project specifies a non-standard source directory but uses the standard Maven layout, but this should at least get you into a working state within Eclipse.

Why does IntelliJ give me "Package doesn't exist" error?

I'm trying to use the barbecue barcode printing library. I have successfully added the library to IntelliJ through project structure add library. Then I imported the packages and wrote the methods, which gave me no error. The packages were available in the class.
But when I compile it gives me the error:
error: package net.sourceforge.barbecue does not exist
How can this be?
I'm coding in ubuntu, is there any other place to which I have to add the library?
Just reimport didn't work. Following worked for me.
File -> Invalidate Caches /Restart
Then
Build -> Rebuild Project
That will reimport maven project.
Note : You need to invalidate the cache AND ALSO rebuild the project.
I tried to "Maven > Reimport" but the only thing that actually fixed it was to close the project, delete the .idea directory, and reopen the project.
None of the 13 existing answers worked for me. However, I could resolve the issue by first removing all modules:
open File > Project Structure...,
go to Modules tab,
select all modules and press the remove button,
then removing all remaining Maven modules from Maven tool window:
select all modules,
right click on them,
press Remove projects,
and then adding them again in Project tool window:
right click on root pom.xml,
press Add as Maven project,
now unignoring any ignored modules from Maven tool window:
select all ignored (grey) Maven modules,
right click on them,
press Unignore,
and finally rebuilding using Build > Rebuild project. This assumes that a mvn clean install already happened.
Right click your project / Maven (at bottom) / Reimport
Edit, much later: I also saw this happen much more frequently when I had the Clover plugin installed. Drop that plugin like a bad habit!
In my case the only thing that worked is:
mvn idea:idea
The good thing is that you don't have to delete .idea folder or .iml files and loose all configuration. Everything will be preserved.
(Possibly something like gradle idea works for gradle too).
menu -> build -> Rebuild Project
has worked for me
(Invalidating caches without this step doesn't help)
I did re-import all maven projects. This worked for me.
If you added a library to the project structure (rather than via maven, that would be different), be sure it is included as a dependency for the relevant module.
Project Structure -> Modules -> Dependencies
It's a very annoying problem which happens quite often. Especially after switching to a different git branch. It wasted me way too much time to troubleshoot this kind problem. I have tried all the methods above. But I can't find a reliable way. Here I just summarize those steps which could help in my situation. Jetbrains, please fix this issue to save your customer's precious time.
Make sure do a success command line build (If UT failed, please ignore UT by using -Dmaven.test.skip=true.
In the "Maven Projects" view, try to use "reimport" all the maven project.
In the file menu, use "Invalidate Caches"
Delete .idea folder, basically create the workspace from scratch. (That's the only reliable way can solve this issue)
In my case the problem was that there was a different repository directory configuration in IntelliJ and in settings.xml file.
Check both repository directories are the same:
IntelliJ (File > Settings > Build,Execution,Deployment > Build Tools > Maven )
settings.xml
(usually in C:\Users\myuser\.m2 or /home/myuser/.m2)
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<localRepository>C:\Users\myuser\.m2\repository</localRepository>
...
</settings>
After fixing directories run:
Generate Folders and Update Sources for All Projects
Reimport all maven projects
Tried all the above approaches, didn't work.
Finally running maven clean install solved it!
Quit IntelliJ, remove every .idea directory:
rm -Rf **/.idea/
and restart.
Invalidate Caches/ Restart and then Build -> Rebuild Project helped for me
I tried all appreciated answers and none of them solve my problem!
According to Intellij community, there is a bug with Maven builds in 2020.1 and 2020.1.1 versions: https://youtrack.jetbrains.com/issue/IDEA-237320?_ga=2.235486722.203129946.1591253608-322129264.1584010541
Please try to run on 2019.3.4 version (Its worked for me from the first time)
You can download from here
https://www.jetbrains.com/idea/download/previous.html?_ga=2.190043688.203129946.1591253608-322129264.1584010541
Similar to cvdr. Too high a Java version can be the problem.
A collegaue just have this problem with multiple java sources in our test project. She had just updated to a later Intellij and when we investigated none of the rebuild options worked but Intellij seemed to have 'bumped' the project Java settings to Java 11 (I guess it takes highest installed version on upgrade install?) Setting it back to Java8 and the project compiles successfully.
Go File>Project Structure > Project Settings > Project and select the right ones in the drop downs.
I got this error after I changed pom, and I fixed it by execute:
mvn idea:module
it works for me
Here is a solution worked for me:
Disable the "Use --release option for cross-compilation like the following in intellij idea:
got Settings -> Build,Execution,Deployment -> Compiler -> Java Compiler and disable:
Use '--release' option for cross compilation(java 9 and later)
As someone who only occasionally needs to do Java work, this was very annoying. Inevitably, packages would have been added since the last time I ran our server inside IntelliJ and it would fail to build. I found what seems to be an easier solution: just don't build within IntelliJ. Build from the command line via Maven, then make sure that the run configuration does not list Build as a "Before launch" task.
I tried
"Maven > Reimport"
Deleting the .idea directory, and reopening the project.
File -> Invalidate Caches/Restart then Build -> Rebuild Project
Deleting what is inside local .m2 folder, and downloading dependencies again.
Running mvn idea:idea in Maven console (Though this command is obsolete, I had to try.)
in different combinations.
But going from Intellij 2020 version to 2019 solved my issue.
I had this problem in IntelliJ 2020.3 and tried the invalidate cache option and rebuild, but the problem persisted. The only thing that fixed it was to rename the package and rename it back to what it was originally.
I had the same problem and it was fixed for me by changing the "Maven home directory" in Settings from "Bundled" to my locally installed maven. Perhaps this triggered some kind of refresh somewhere since I had not changed this setting for months without any issue.
What happens here is the particular package is not available in the cache. Resetting will help solve the problem.
File -> Invalidate Caches /Restart
Goto terminal and build the project again
./gradlew build
This should download all the missing packages again
If you are trying the suggested ways and still no chance, be sure about your order:
Delete your .idea/
Invalidate and Restart Cache afterwards
Import maven projects from your maven tool
If you did not invalidate and restart cache just after deleting your .idea/, Intellij keeps generating it and that was keeping error in my case.
I had the same issue with my unit tests. I created tests on my master branch and early everything worked well, no matter what branch I was using. But when I switched again to master branch, tests did not work anymore.
What helped me was to:
close intellij -> delete .idea file from directory -> open project again by pom.xml (idk if it matters what way you open the project, but first time when I tried to open it normally by intellij, it still dit not work) -> reload all maven projects from right menu -> rebuild project and that's it, everything works now
I had the same problem. I fixed it by applying the android-apt plugin https://bitbucket.org/hvisser/android-apt
Maven reimport, rebuild and invalidate caches did not work. I solved it by opening a terminal and executing maven clean install in the root folder project. (IntelliJ was opened and I was able to see the IDE updating and triggering reindexation while maven was doing his job)
The above solutions didn't work for me. I had to add the dependency explicitly in the pom.xml.
Just add your jar under resources/library and then add it as a dependency in your pom.xml like:
<dependency>
<groupId>your-jar-group-id</groupId>
<artifactId>artifact-id</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/resources/library/name-of-jar.jar</systemPath>
</dependency>
Try this out if none of the above work.
Delete your .idea/
Invalidate and Restart Cache afterwards
Re-import project
If you do not want to destroy .idea, you can try :
open Project Structure > Modules
unmark the java folder as a source folder
apply / rebuild
then mark it again as a source folder
rebuild
In case you're facing very weird "unable to resolve java, sun packages problem", try the following:
Open Project Structure and change Project SDK to another version, example: java 8 -> 9; 11->13, etc, and wait until it re-index all jdk's jars. Switch between jdks with same version may not work! (Ex: jetbrains jdk11 -> openjdk 11)
Open a new project (or create a empty one); pause new project's indexing; close the old one; start indexing; open the old project and pause the new project's indexing and wait.

imported maven project does not appear as java project. Shows folders

I checked out the existing project source code from SVN to a folder in my system.
Then I opened eclipse. Import Project-> Existing Maven Project.
It imported without issues. However, Project Explorer shows it as just folders instead of packages. (Like when we create a package and then add classes to it, it shows a different icon for package root). I opened Navigator and Package Explorer as well. But they are showing them as folders as well.
I tried:
mvn eclipse:clean
mvn eclipse:eclipse
on the root of the project. But it did not help.
Can anyone help on this one?
My folder structure:
ecs->
ecs-ejb->
src/java/main/com/xxx
pom.xml
ecs->ear->
src/java/main/com/xxx
pom.xml
pom.xml
Try to:
Right click the project->Configure->Convert to Maven Project
---- Edit ----
If this doesnt work, it is likely that someone checked in their environment files into your SVN. If they checked in:
.project
.classpath
.settings/
They could be conflicting with your environment (different settings/plugins/versions of eclipse...). Try dropping your project, deleting the folder/files, then remove these files from SVN, and repeat your initial process. All of these files/folders will get generated during the import to eclipse.
---- Edit 2 ----
Per your recent edit to the question, you have a multi-module project. If you only did this on the parent project, then there is no source folder. So you wouldn't see it. You should:
File->Import...
Choose Existing Maven Projects, Next
Set the Root Directory to ecs/ecs-ejb, Finish
Repeat for all other modules.
In eclipse, each module of a multi-module maven project needs its own eclipse project.
Right click the project->Configure->Convert to Faceted Form
This solution worked for me
Possibility is Module doesn't have .classpath.
Kindly right click on Module and Change Project fact as Java.
else
If you are using command Prompt.
1. mvn eclipse:clean
2. mvn eclipse:eclipse
else
Delete Project from Eclipse don't delete content from disk. remove .classpath and .project
Re-import as maven existing Project
Right Click->Maven->Update Project.
Above works perfectly fine for Eclipse Juno and solves the problem.
You just need to change the nature of the project.
For MAC->
-> Right click on project
-> Properties -> Check Project Natures
-> Then add or remove accordingly if you are having a maven project then add Maven, add Java
I had the same problem. I tried a lot of things that I read on internet but the only way that I found to solve my problem was exclude all of my workspace files (.metadata folder) and create another one.
After that, I imported a existing maven project and all my problems are gone.
I also faced a similar issue. I resolved it by downloading the correct apache maven plugins in the maven repository org / apache/ Maven/ plugins. IN my case, everything was working fine earlier and I had deleted .m2 repository completely. After that I started getting these issues with same iDE and newer IDE versions as well. The pom.xml showed error related to lifecycle mappings. On downloading the correct plugin, the workspace worked fine.
Delete the metadata folder. Checkout again but select "Checkout as a project configured using the New Project Wizard" instead of "Checkout as a project in the workspace".
Then a New Project wizard will open, type maven there and select "Checkout Maven Projects from SCM" preferably or "Maven Project". It should work. Remember this step should be performed for Maven Projects only. For normal Projects just select Java Project or whatever relevant type Eclipse project it is.
Check and make sure you have eclipse pointing at a Java JDK directory instead of a Java JRE directory.
I had just installed eclipse and only the JRE was in the settings. I added the JDK path, changed it to the default and clicked on Maven -> Update project. Then the packages appeared in Package Explorer.
The hint that helped me figure this out is that when I tried to use the refactor to rename a class, it wouldn't do it, complaining that it wasn't a JDK.
Instead of importing as Existing Maven Project, follow below steps
I assume that your folder has pom.xml, src/main and src/test.
Step 1: Right click > Create New > Java Project > Chose the project folder has pom.xml
Step 2: Right Click on Project > Configure > Convert to Maven project
I got it working using Proyect --> Properties --> Project Facets
In my case was a web project so I checked Java and Dynamic Web Module
Try right click on project, Maven->Update Project... (or similar, the link name changes depending on version)
This works for me when adding new folders, but I have not encountered the problem when importing a project.
Right click the project, then click Configure -> Convert to Maven Project. If the packages still display as ordinary folders, then right click on the folder one level up (the one that is supposed to be the source folder), then click Build Path -> Use as a source folder.
Here is my solution please close the Project Explorer at the left top and open again.
(or)
1). Right Click on your miscellaneous project and choose project Explorer if available.
Adding projects to working sets should help
try it ->
right click the project -> Maven -> Assign Working Sets... -> Add projects to working sets

How to refresh external Jars in Eclipse project (Java)?

I have a Java project in Eclipse which includes a couple of external jar files. These external jar files are being rebuilt through a different process (not Eclipse, Ant). Those changes are not being reflected on the Eclipse project even if I refresh the project. If I close the project and reopen, it works.
Any suggestions on how I could expedite the project without having to close and reopen? Thanks.
Try right click on the project and select refresh.
If that does not work, go to the Project menu, clean, and check your project.
In the package explorer view, you can select the jar and do right click and refresh.
Is not available in Eclipse Version: 3.6.1, Build id: M20100909-0800. I think that version's current. A reportable bug IMHO.
Restarting Eclipse works.
In the package explorer view, you can select the jar and do right click and refresh.
If the above answers did not work for you and this jar is on your build path. Do following steps :
1- remove the jar from the build path(right clicking the jar -> Build Path -> Remove from build path)
2- add the jar to the build path(right clicking the jar -> Build Path -> Add to build path)
This worked for me and is much easier than restarting Eclipse.
If refreshing the project, cleaning the project, refreshing referenced jar (F5) does not work, it might be Maven dependency still referencing old version. If your project uses Maven, remove this jar temporarily from Maven Dependencies list (you can update it later). It worked for me..
I think you should check if you open auto build project option.
Project 、Auto Build Project
Everytime I change the method code block , Eclipse would help me build the project to jar.

Categories

Resources