Error while create Scala-Maven project on IntelliJ - scala

I am trying to create a Scala-Maven project on IntelliJ. I had downloaded the plugin Scala. When I try to create a project from IntelliJ's file menu like below:
Once I click on NEXT and FINISH, I see the Idea tries to build the project and fails with this message:
"C:\Program Files\Java\jdk1.8.0_151\bin\java.exe" -Dmaven.multiModuleProjectDirectory=C:\Users\Bobby\AppData\Local\Temp\archetypetmp "-Dmaven.home=C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.1.4\plugins\maven\lib\maven3" "-Dclassworlds.conf=C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.1.4\plugins\maven\lib\maven3\bin\m2.conf" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.1.4\plugins\maven\lib\maven3\boot\plexus-classworlds-2.5.2.jar" org.codehaus.classworlds.Launcher -Didea.version=2018.1.4 -s C:\Users\Bobby\.m2\settings.xml -Dmaven.repo.local=C:\Users\Bobby\.m2\repository -DinteractiveMode=false -DgroupId=com.sample.programs -DartifactId=Abcd -Dversion=1.0-SNAPSHOT -DarchetypeGroupId=org.scala-tools.archetypes -DarchetypeArtifactId=scala-archetype-simple -DarchetypeVersion=1.2 -DarchetypeRepository=http://scala-tools.org/repo-releases org.apache.maven.plugins:maven-archetype-plugin:RELEASE:generate
[ERROR] Error executing Maven.
[ERROR] 1 problem was encountered while building the effective settings
[FATAL] Non-parseable settings C:\Users\Bobby\.m2\settings.xml: only whitespace content allowed before start tag and not x (position: START_DOCUMENT seen x... #1:1) # C:\Users\Bobby\.m2\settings.xml, line 1, column 1
[ERROR] Maven execution terminated abnormally (exit code 1)
I checked the maven folder in my desktop and these are the sub folders inside .m2/repository:
Could anyone let me know what is the problem here and what should I do to make this work ?

I tried to follow your exact steps but didn't get the same error. I'm using IntelliJ IDEA Community 2016.2 .
From the error message you received, it looks like you might have a corrupted .m2\settings.xml.
I noticed that this file doesn't exist by default on my computer. I tried to create one with only the 'x' character, and that causes an error on my maven build (but not exactly the same as yours).
Try to check that file, and make sure it's content is xml formatted, or erase it completely (if you are sure it's safe).
There is a UI way to see that document in IntelliJ:
1. Open the Maven Project tab
2. Right click on your project title
Maven Project Tab
3. Select " Open 'settings.xml' "
opened settings.xml
4. The setting file content is displayed in your IDE and can be modified
Hope that helps

Related

IntelliJ Cannot Import sbt Project

I have upgraded IntelliJ to version CE 2017.3 from a CE 2017.2.5, and now I cannot build my sbt project. The build gets stuck on the first step:
"Build: sync
MyProjName: syncing...
dump project structure from sbt"
I have deleted the .idea directory and the the MyProjName/project/target directory. I did an sbt build from the command line, which worked.
Then I started IntelliJ again and tried to import MyProjName/build.sbt as a project. I have also logged out/in. Did this several times. The import never progresses past this step.
I work behind a firewall, but I have checked my proxy settings, and they are correct and unchanged from the previous version (if this matters).
How can I troubleshoot / fix this?
The sbt version is 0.13.6. Scala plugin 2017.3.10.
From the log:
IDE: IntelliJ IDEA (build #IC-173.3727.127, 27 Nov 2017 09:32)
OS: Windows 7 (6.1, amd64)
JRE: 1.8.0_152-release-1024-b6 (JetBrains s.r.o)
JVM: 25.152-b6 (OpenJDK 64-Bit Server VM)
I solved the sync issue following info here:
https://youtrack.jetbrains.com/issue/SCL-13024
Key info is "It seems that sbt is trying to re-resolve 'sources' and 'docs' for sbt plugins that are not available at all. If properties to download "Library sources" and "sbt sources" are disabled, then time to dump the structure is reduced from 'forever' to less than 1 minute."
That is , in IntelliJ IDEA, clear the check box "Library sources" under "Project level settings" for Build Tools sbt in IDEA preferences. As shown in image below:
The only way I could work around this was by running sbt clean compile in the SBT console/cmd line first, then refreshing the SBT project in IntelliJ.
Open a terminal inside IDEA by pressing Alt F12 or use sbt shell
Run sbt - if it is first time it will take some time.
Run clean
Run compile - it will download dependencies you have in your project.
Close IDEA project (File -> Close Project) and open it again.
Note: if it asks to import in the right-bottom of the screen activate Enable auto-import, if you don't like to keep it enabled (like me) press Import, cancel the syncronyzation and then Refresh sbt project again. When you try to use import in the middle of a sync it gets stuck with dump project structure from sbt message.
The Refresh sbt project is located at this corner of the Build Sync window - highlighted below:
I have not found a way to make this work in IntelliJ Idea CE 2017.3, so I have reverted to CE 2017.2.5
IntelliJ appears to limit the efficiency of the already slow sbt update. I recommend using sbt-coursier instead. It was written specifically to improve dependency update time, and on one large project I'm involved in it improved dependency update time by about 2 orders of magnitude.
Uncheck "Use auto-import" in Preferences > Build, Execution, Deployment > Build Tools > sbt to prevent IntelliJ from auto updating imports on its own
Add addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.3") to your project's build.sbt file
Or install it globally in ~/.sbt/1.0/plugins/build.sbt
Run sbt update on the command line
If you see [error] java.lang.NoClassDefFoundError: org/vafer/jdeb/Console, then add the following to ~/.sbt/1.0/sbt-coursier.sbt.
import coursier.Keys._
classpathTypes += "maven-plugin"
See coursier issue #450 for more information about that error.
(Optional) Re-enable auto-import from step 1, as subsequent transactional dependency updates may be faster.
I meet the same problem! I delete the directory ~/.sbt/0.13, then it works. You can delete the sbt directory you used.
What worked for me was to increase the memory for SBT inside IntelliJ. On my Mac: preference -> Build, Execution, Depoyment -> sbt
then change "Maximum heap size" from 768MB to 2048MB and then everything was successfully imported after few minutes.
Custom SBT version works for me.
IntelliJ IDEA Preferences -> Build,Execution,Deployment -> Build Tools -> sbt -> Launcher
Choose Custom
For me, simply checking use sbt shell for both build and imports worked.
Had an older checked out project causing this issue. Did the usual rm -rf .idea + re-import but it kept getting stuck. Tried all sorts of things, but when finally fixed it for me was not just deleting the top-level target folder, but instead doing
find . -name target -type d -exec rm -rf {} \;
Next open / import went flawlessly. (This was on 2018.1.5, 2018.1.6 and 2018.2 RC.)
I have suffered from same problems after upgrade intelliJ to 2017.3
But it works fine now.
I think intelliJ couldn't pass the 'No proxy for' option to sbt.
so, I added
-Dhttp.nonProxyHosts="host1|host2"
option in File > Settings > Build, Excution, Deployment > sbt > VM parameters
Simply unchecking 'sbt sources' did the trick for me
I was also facing this issue. Below two configurations worked for me. I tried to confirm this setting in many new sbt projects, for all it worked.
(1) uncheck "Library sources" under "Project level settings" for Build Tools sbt in
IDEA preferences
(2) -Dhttp.nonProxyHosts="host1|host2"
option in File > Settings > Build, Excution, Deployment > sbt > VM parameters
I hit similar issue but found it's related to waiting for locks
~/.sbt/tool/sbt.boot.lock
~/.ivy2/.sbt.ivy.lock
Maybe if killing IntelliJ IDEA and no one will release the lock files, the issue is resolved after deleting locks files manually

How do I find the correct Maven archetype project for developing with Scala in Eclipse?

I'm having problems trying to just create a Maven project using Scala (v2.11.6) within Eclipse (Luna). The instructions here says to install both plugins below.
Maven Integration in Eclipse
m2eclipse-scala connector
Both plugins can be installed by using the m2eclipse-scala update site. So here's what I did in my first attempt.
Download Eclipse Luna (for JavaEE developers)
Install "both" plugins above by using the m2eclipse-scala update site.
When Eclipse loads up, I attempt to create a Maven project, and the archetype I want to use is Group Id=net.alchim31.maven, Artifact Id=scala-archetype-simple, Version=1.5. However, this archetype never shows up when I enter in "scala-arch" in the filter text field.
The only project I see is the one with Group Id=org.scala-tools.archetypes, Artifact Id=scala-archetype-simple, Version=1.2. When I select this archetype to use, I get a bunch of error messages in Eclipse.
error while loading ConsoleRunner, Scala signature ConsoleRunner has wrong version expected: 5.0 found: 4.1 in ConsoleRunner.class
error while loading JUnit4, Scala signature JUnit4 has wrong version expected: 5.0 found: 4.1 in JUnit4.class
error while loading Specification, Scala signature Specification has wrong version expected: 5.0 found: 4.1 in Specification.class
In my second attempt, I try to download the pre-packaged bundle (Scala IDE for Eclipse). Again, when I attempt to create a Scala Maven project, I don't see the Maven archetype for Group Id=net.alchim31.maven (only for Group Id=org.scala-tools.archetypes).
Any ideas on what I'm doing wrong here? Or where I can find a vanilla Scala Maven project to import/modify and use for my own purpose?
Here's how I got it to work. It seems all the archetypes aren't available, so based on this answer, I created a remote catalog
Before
So do this
Go to [Windows] → [Preferences] → [Maven] → [Archetypes] → Add Remote Catalog and create the catalog, then Apply
For copy-pasting:
Catalog File: http://repo1.maven.org/maven2/archetype-catalog.xml
Description: Remote Archetypes
Go back to creating a new Maven project. Select the Remote Catalog from the dropdown. It will take a few moments to gather all the archetypes. You can see the progress at the very bottom right of the IDE. When it's done, you should be able to see the archetypes
After
Create your project with groupId and artifactId and such.
Right click the project, then from the context menu [Run As] &rarr [Maven Build]. In the dialog, type clean package into the goals. The run. The project should build and run the tests.
For me at first I got an error on the build. It was because my default environment is using Java 8. I'm pretty new to Scala, so I'm not sure is there is a problem with Scala and Java 8 or not (I think it's the Scala version in the pom (2.10.0)). But what I did to get it to work was just change the Java version used in the IDE to Java 7.
Basically just go to [Windows] → [Preferenes] → [Java] → [Installed JREs] → Add → [System VM] → Next → Directory → Find the directory of the Java home (version 7) → Finish → Then in the list tick Java 7.
Then build again. It should work. Good Luck!
One point I want to add, If you are getting following error while installing the archetype showed in image 1
Can't resolve Archetype
org.glassfish.jersey.archetypes:jersey-quickstart-webapp:2.21
org.eclipse.core.runtime.CoreException: Could not resolve artifact
org.glassfish.jersey.archetypes:jersey-quickstart-webapp:pom:2.21
Image 1:
Then before procedding with the solution specified above, try to complete these steps in eclipse.
I faced the same problem and chanced upon this SO question, as well as the answer, given by #peeskillet (many thanks). I am using:
Maven 3.3.3
Eclipse Luna Scala IDE 4.0.0.-vfinal-20150305-1644-Typesafe
Scala 2.11.6
JDK 1.8
After following the steps exactly as given here, I hit a wall. When I chose the right archetype (net.alchim31.maven), I was greeted with this error:
Could not resolve artifact net.alchim31.maven:scala-archetype-simple:pom:1.5
Suspecting that the maven embedded in eclipse was acting funny, I visited [Windows] -> [Maven] -> [Installations] and added local installation of maven (whatever is set to M2_HOME in my shell). But, no luck!
Exasperated, I visited this site: Scala Doc and switched back to command-line as this page instructs. Surprisingly (to me, at least), it worked. A maven-Scala project was created in the present directory, which I could import into Eclipse.
Just so that I am not misunderstood, I am not suggesting that #peeskillet's answer is wrong. Just wanted to share another way of creating a maven-scala project on Eclipse, in case it helps someone. I have not yet understood, why Eclipse-Scala-IDE is yet to give that 'Aha' feeling.
After you have successfully created the scala-maven project as described above, you will probably see an error "Type not found: type JUnitRunner specs.scala". In that case, manually add the following XML snippet to your pom.
<dependency>
<groupId>org.specs2</groupId>
<artifactId>specs2-junit_${scala.compat.version}</artifactId>
<version>2.4.16</version>
<scope>test</scope>
</dependency>
Moreover, to avoid errors when running mvn test,
[ERROR] scalac error: bad option: '-make:transitive'
You also need to delete the following line from the pom.xml file:
<arg>-make:transitive</arg>

Eclipse Gradle Plugin 'could not fetch model of type'

I am running Eclipse Luna on OS X with Gradle IDE 3.6.1 and anytime I try to select a project from the gradle tasks panel I get the following error:
org.eclipse.osgi.internal.framework.EquinoxConfiguration$1
Could not fetch model of type 'EclipseProject' using Gradle distribution
'https://services.gradle.org/distributions/gradle-2.0-bin.zip'.
Has anyone else run into this error? I can get to the URL specified to download the file myself. So, network connectivity shouldn't be the problem.
The problem is for the java version configured by default on the IDE (Eclipse or Spring Tool Suite). The error is the following:
To fix it, you can set the Java version supported by the Gradle version in Configure Workspace Setting option.
Finally, you can refresh your project o continue with your creation. Later all will be perfect.
I had the same error in Eclipse Neon (version numbers were different, but otherwise same error). It looks like several different things can cause this error, but for me it was an incorrect property in [MyProject]/.settings/org.eclipse.buildship.core.prefs.
I had
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
but it needed to be
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(2.13))
2.13 should be replaced with whatever version number output you get from gradle -version.
Coming back to add this:
It turns out, the actual root problem was an incompatibility between Gradle versions. My build.gradle file worked fine with an old version of Gradle, but uses things that were deprecated and removed in later versions.
Solution is to click Finish immediately in the wizard instead of Next, and then fix the issues in the build.gradle.
Bad reference in config.
Overwrite configuration:
Project -> Properties -> Gradle -> Override workspace settings ->
Specific Gradle version -> 4.x
You need to update Gradle
Goto:
Select 'Help > About Eclipse' (on Macs this is 'Eclipse > About Eclipse').
Click the 'Installation Details' button to display the installation details dialog. Look in the 'Installed Software' tab to see all the installed plugins.
Search for Gradle(Eclipse Plug-ins for Gradle) and Update.
It might take some time for first time after that.
Reason why it happens, cause new version of gradle is available to download. Once you download new version of gradle, your error will go away.
http://gradle.org/downloads
I had the same error message using Eclipse 4.5
In my case the build file was having a error and I had to modify this line
eclipse.classpath {
plusConfigurations += configurations.providedCompile
}
into this
eclipse.classpath {
plusConfigurations += [configurations.providedCompile]
}
After that everything worked again.
I met the same problem, somebody suggested that the gradle project may be build by a old version.
I solve the problem by the following step:
modify the configuration in Eclipse, perfrence ->gradle ->gradle distribution . point it to an older version.
delete the file in ./gradle/wrapper
reload the program
In my case, I forgot to put ending apostrophe ' for a value
I ran into a similar issue recently - even blowing away the project and repulling a fresh copy from git didn't fix it. I realized it wasn't specific to the project when I reproduced it outside of Eclipse:
$ ./gradlew tasks
FAILURE: Build failed with an exception.
* What went wrong:
Expecting a stack map frame
Exception Details:
Location:
build_euvk0e0guiuwrf8fgn8svi2fy.run()Ljava/lang/Object; #16: aconst_null
Reason:
Error exists in the bytecode
Bytecode:
0x0000000: 2abb 0022 592a 2ab7 0025 ba00 3300 00b0
0x0000010: 01b0
What did fix it was removing the gradle cache:
$ rm -r ~/.gradle/caches
$ ./gradlew tasks
Somehow the version of gradle there had become corrupted (possibly related to Eclipse groovy plugin - I had this issue regularly until uninstalling it), and blowing it away forced it to get a fresh copy.
Hopefully this answer helps someone else avoid pulling out their hair.
I had a very similar issue and removing the following from my build.gradle fixed it. The same bit of config works in all other Gradle projects I have but for some reason not this one...
allprojects {
...
apply plugin: 'eclipse-wtp'
...
// remove this eclipse config to make the error go away
eclipse {
classpath { defaultOutputDir = file('build-eclipse') }
}
...
}
Open the CMD and enter there gradle --gui, change the settings of the gradle gui in the register Setup to Stack trace Output: Full Stack trace [-S] and the log level to info. Then change the current directory to the directory your build.gradle file is located and then go to the first register and let process the gui this files.
An error message should be displayed. There you find out what is wrong with your build.gradle file. In my case there was a folder missing and this causes this error.
This error can also be caused by a syntax error in the previous line of build.gradle. If so, the error has nothing to do with the Gradle or Eclipse version you are running. See this question
In my case i changed the Gradle version from 4.7.rc2 to4.6 and then it started to work.
I am on eclipse Oxygen (4.7.2), I was getting similar exception while importing the project and this worked for me:
While importing on windows Import Options
Click Configure Workspace Setting (which will take to preference window)
Select Local Installation directory (for me 'graddle wrapper' was selected)
apply, close and continue import
Below is the error I was getting
Loading Gradle project preview failed due to an error in the referenced Gradle build.
Could not fetch model of type 'GradleBuild' using Gradle distribution 'https://services.gradle.org/distributions/gradle-3.5-bin.zip'.
_BuildScript_
org.gradle.tooling.BuildException: Could not fetch model of type 'GradleBuild' using Gradle distribution 'https://services.gradle.org/distributions/gradle-3.5-bin.zip'.
at org.gradle.tooling.internal.consumer.ExceptionTransformer.transform(ExceptionTransformer.java:51)
at org.gradle.tooling.internal.consumer.ExceptionTransformer.transform(ExceptionTransformer.java:29)
at org.gradle.tooling.internal.consumer.ResultHandlerAdapter.onFailure(ResultHandlerAdapter.java:41)
at org.gradle.tooling.internal.consumer.async.DefaultAsyncConsumerActionExecutor$1$1.run(DefaultAsyncConsumerActionExecutor.java:57)
at Caused by: java.lang.ClassNotFoundException: _BuildScript_
at org.gradle.groovy.scripts.internal.DefaultScriptCompilationHandler$ScriptClassLoader.loadClass(DefaultScriptCompilationHandler.java:386)
... 77 more
None of the solutions worked for me and I'm having the same errors on STS 4 with eclipse Version: 2.2.600.v20190605-1800. My steps were:
Delete the project from my workspace
./gradlew cleanEclipseWtp cleanEclipse eclipseWtp eclipse
Import the project as an existing eclipse project (not an existing gradle import)
That worked!
Deleting .gradle folder from the project resolved my problem.
I got this error with Eclipse 2021-06, Java 1.8.0, gradle 4.4.
I tried deleting gradle wrapper binary folder, predefining gradle version, etc.
The thing that helped was just specifying gradle home directory and java home directory after selecting overriding workspace configuration.
Eclipse 4.4.1 broke Gradle Eclipse support with non-string values in system properties.This is fixed in the latest Gradle for the 3.6.2 release. Update your Gradle form this update-site: http://dist.springsource.com/snapshot/TOOLS/gradle/nightly

Unable to reimport Grails project into GGTS / STS?

I have copied a grails project to the workspace folder -
and try to import. The following error is shown:
Invalid project description.
OK
C:\Users...\workspace-ggts-3.5.1.RELEASE\ overlaps the location of another project: ''
How can I can clean the workspace correctly (delete the project properly) so that this message does not appear? I did ensure that the project name under .projects did
not exist prior to import - but message still indicates an overlap?
I then open project and Run As Grails Command (run-app).Grails home is set to: C:\grails-1.3.7\ -
and get
Base Directory: C:...
Resolving dependencies...
Dependencies resolved in 470ms.
C:... does not appear to be part of a Grails application.
The following commands are supported outside of a project:
add-proxy
clear-proxy
create-app
create-plugin
help
list-plugins
package-plugin
plugin-info
remove-proxy
set-proxy
Run 'grails help' for a complete list of available scripts.
Note that I had imported the project successfully before (as a Grails project) and
have deleted since etc.
I have also tried moving to other folder which I do not want to do.
How can I resolve the above?
Thank you
Simon

GWT: Eclipse giving "Unable to find module" error when I try and run web app

I'm using Eclipse Indigo, Maven 3.0.3, and GWT 2.4. I have imported my Maven project into Eclipse and enabled GWT support. However, bafflingly, when I right click on my projecdt and select "Run As" -> "Web Application", I get the error in the Console pane ...
Loading modules com.myco.clearing.commons.xml.ProductPlusJUnit
[ERROR] Unable to find 'com/myco/clearing/commons/xml/ProductPlusJUnit.gwt.xml' on your
classpath; could be a typo, or maybe you forgot to include a classpath
entry for source?
[ERROR] shell failed in doStartup method
The bizarre thing is, I have no file com/myco/clearing/commons/xml/ProductPlusJUnit.gwt.xml. The closest thing I have is a file at src/main/java/com/myco/clearing/product/ProductPlusJUnit.gwt.xml. Where is Eclipse getting this and how I can I tell it to launch the correct entry point module (which is src/main/java/com/clearing/product/ProductPlus.gwt.xml)?
Right click on 'java' folder in 'src/main/java' and select 'Build Path' --> 'Use as source folder'. Eclipse should then detect module and build project automatically.