I'm using VS Code for Java development and working with other developers who use IntelliJ. I'd like to use the Organize Imports command (Shift+Alt+O) to clean up my imports, but I don't want to fight over import order with every commit. So I'd like to configure VS Code to organize the imports in the same order as IntelliJ's default. Does anybody have a configuration that would do this?
If this is not possible, is there a workspace configuration I can apply to both VS Code and IntelliJ so that the two IDEs will agree, even if they aren't agreeing on IntelliJ's default?
We were able to get it the almost identical with the following config tweaks.
VS Code:
{
"java.completion.importOrder": [
"",
"javax",
"java",
"#"
]
}
IntelliJ
The only difference from the IntelliJ default is a new line between import javax... and import java....
It's possible to get VS Code and IntelliJ to agree on a standard format, as long as that standard format:
Puts static imports at the top*
Separates all specific sections with empty lines
Puts everything not in its own specific section in a catch-all section at the end*
Never uses wildcard imports
Not actually true; static imports can be positioned in VS Code with '#', and everything else can be position in VS Code with ''.
IntelliJ's default settings don't work for this, but it is flexible enough to be reconfigured. Here are the files to add to a project to make just that project set up consistent rules for both IDEs (make sure they are not excluded in .gitignore).
Rule: The following groups separated by empty lines: Static imports, java.*, javax.*, everything else.
.vscode/settings.json:
{
"java.completion.importOrder": ["java", "javax"],
}
.idea/codeStyles/codeStyleConfig.xml:
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>
.idea/codeStyles/Project.xml
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JavaCodeStyleSettings>
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="true" />
<emptyLine />
<package name="java" withSubpackages="true" static="false" />
<emptyLine />
<package name="javax" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="false" />
</value>
</option>
</JavaCodeStyleSettings>
</code_scheme>
</component>
Related
If I create step in Cucumber .feature file that is not implemented I get snippet in logs.
But if I make error in .feature file like starting new line with "Andd" or with anything but keywords (given, when..) then I get error in IntelliJ "Unexpected element" which is underlined and that's great.
But despite that when I build project I get "success build".
Also when I go further and run Cucumber tests I get
"0 Scenarios, 0 Steps found." and no explanation why.
Is there any build parameter that can be added to mark such build unsuccessful?
Is there any way to point to such errors?
Edit: when running from cmd 'mvn test..' I get nice stack trace.
Problem is only when running in Intellij > Run/Debug Configuration.
Sample .run.xml that I am using:
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Feature: testFeed" type="CucumberJavaRunConfigurationType" factoryName="Cucumber java" nameIsGenerated="true">
<option name="CUCUMBER_CORE_VERSION" value="5" />
<option name="FILE_PATH" value="$PROJECT_DIR$/src/test/resources/features/testFeed.feature" />
<option name="GLUE" value="com.testing.stepdefiniton" />
<option name="MAIN_CLASS_NAME" value="io.cucumber.core.cli.Main" />
<module name="testing" />
<option name="PROGRAM_PARAMETERS" value=" --plugin org.jetbrains.plugins.cucumber.java.run.CucumberJvm5SMFormatter" />
<shortenClasspath name="NONE" />
<option name="SUGGESTED_NAME" value="Feature: testFeed" />
<option name="VM_PARAMETERS" value="-Dspring.profiles.active=local -Dcucumber.filter.tags="#test"" />
<option name="WORKING_DIRECTORY" value="$MODULE_WORKING_DIR$" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="io.cucumber.core.cli.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
There are two parts to this question
You usage of IntelliJ (I can't help you with this)
Your usage of Cucumber (maybe I can help here)
Cucumber is telling you that it can't find any scenarios or any steps. Its not going to contribute until you can fix that. You need to either try running Cucumber from the command line, or configure IntelliJ correctly so it can find the features and steps when running cucumber.
I'm using Spotless with Gradle. I've configured it to use Eclipse's JDT Code Formatter:
spotless {
groovyGradle {
greclipse("4.21.0").configFile("${rootDir}/config/spotless/eclipe_groovy_formatter.xml")
}
java {
eclipse("4.21.0").configFile("${rootDir}/config/spotless/eclipe_jdt_formatter.xml")
endWithNewline()
importOrder("", "javax", "java")
indentWithSpaces(2)
lineEndings(LineEnding.UNIX)
removeUnusedImports()
trimTrailingWhitespace()
}
}
The content of eclipe_jdt_formatter.xml is just:
<?xml version="1.0" encoding="UTF-8" ?>
<profiles version="12">
<profile kind="CodeFormatterProfile" name="Fulgore Team" version="12">
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="80" />
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="false" />
<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="100" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert" />
</profile>
</profiles>
The problem is that I would like to configure the correct setting(s) within the (Eclipse) XML file in order to have the enum values each on its own line.
For instance, this is how it's currently formatting the source code:
public enum Type {
VALUE, OTHER, ANOTHER,
}
...but I would like:
public enum Type {
VALUE,
OTHER,
ANOTHER,
}
If anyone knows the combination of settings I can use within the XML file to accomplish this I would really appreciate it. I've tried a couple of combinations from .formatter and/or .indent without luck.
Try <setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="49"/>
Have a project that I am migrating over from netbeans to intellij.
Intellij recognises the spring config files and gives the warning "please configure/setup spring facet for modules". This requires manually adding these under project structure settings.
I don't want the other team members to all have to do this manually, so I wish to check these settings into git, but according to that, there are no changed files in the project directory (I have standard ignores added to .gitignore). I have also tried searches of file contents for the config file names etc and that turns up nothing too.
So my question is where are the settings stored? In a file that is typically on the ignored list or in a location external to the project directory?
Essentially all the IDEA related configuration for the project is under .idea folder, for example, all the project workspace iteams you can find in the .idea/worksapce.xml, include the spring features you mentioned.
But this is not a good idea to keep those things in your VCs, the .idea folder is ignore default as in the configuration items will store you local env related like the full path to your local gradle, e.g.
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="C:/DevTools/gradle-2.14.1" />
<option name="gradleJvm" value="#JAVA_HOME" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
<option name="useAutoImport" value="true" />
<option name="myModules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>
Here are some files under the .idea folder for my proejct
Update:
For the spring facets, it's under the module .iml file, like
<component name="FacetManager">
<facet type="Spring" name="Spring">
<configuration>
<fileset id="fileset" name="Spring Application Context" removed="false">
<file>file://$MODULE_DIR$/src/main/resources/META-INF/spring/integration-beans.xml</file>
</fileset>
</configuration>
</facet>
</component>
I imported a Leiningen project into Intellij to sit alongside some existing Java & Scala modules. I would like to call functions from those modules from my Clojure module, but I'm not sure how to define this dependency. I went to Project Settings -> Modules and the "Dependencies" tab that's usually there is missing, leading me to believe that I'm not allowed to express dependencies anywhere other than the Leiningen project file (I've played with the Leiningen project editor and can't figure out how to do this there either...).
Here is the .iml file if anyone is curious how Intellij is viewing this module.
<?xml version="1.0" encoding="UTF-8"?>
<module cursive.leiningen.project.LeiningenProjectsManager.displayName="testproject:0.1.0-SNAPSHOT" cursive.leiningen.project.LeiningenProjectsManager.isLeinModule="true" type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/classes" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/dev-resources" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/resources" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Leiningen: clojure-complete:0.2.3" level="project" />
<orderEntry type="library" name="Leiningen: org.clojure/clojure:1.6.0" level="project" />
<orderEntry type="library" name="Leiningen: org.clojure/tools.nrepl:0.2.10" level="project" />
I develop Cursive. I suspect there may not be a good solution for this right now. I'll look at the code and see if I can figure out a way to do it, but it'll require knowledge of how Maven, Gradle or SBT (in your case) represent the modules internally. I'll try to look at this today and let you know. I actually don't know if it's possible in IntelliJ for a Maven project to depend on an SBT project, for example, or a Gradle one.
In the meantime, publishing to your local repo is the only workaround I can think of. Sorry, I know it's clunky.
There's no difference from IntelliJ's point of view between a "normal" project and an IntelliJ one, it's just that Cursive will rewrite a lot of the module configuration on each sync since in theory that configuration should be managed by Leiningen. This is more or less how the Maven integration works.
So, I eventually was able to do this... as dAni suggested, I was able to create a new Clojure project (through IntelliJ this time -- previously I did "lein new clj-test" then tried to import this into IntelliJ), create a Leiningen build file, process that build file, and then see the Dependencies tab for the module in Project Structure.
Still, the REPL could not find the classes. So I had to edit the Run configuration to use nREPL in "a normal JVM process" which let me select the module whose classpath I would presumably be using.
Hate to be the guy to accept my own answer (especially since this has some limitation... I want to use this with Gorilla REPL in the end so will probably devise a different strategy for that) but I think this answers the original question pretty well, hope it helps someone. I think essentially what the above strategy is doing is using Leiningen for dependency resolution but not actually for the REPL, so Leiningen's dependencies are available on the classpath but the REPL is launched some other way via IntelliJ.
IzPack TargetPanel lets one select one target directory. However I need to allow users to choose two (one for apps, one for data). How to do that?
You can create a UserInputPanel and get the path as a variable from the user. Then you can use variable substitution anywhere you want. You'll have to add a userInputSpec.xml file and define your own panels (as many as you want). To get a directory, use <field type="dir" ... >
Example userInputSpec.xml from an application of mine. I include mongoDB with the installer and use this to get some settings.
<userInput>
<panel order="0">
<createForPack name="MongoDB" />
<!-- Other settings like port, ip, username, password-->
<field type="staticText" align="left" txt="Select the catalogue where data will be stored." id="staticText.registry.db.data.text" />
<field type="dir" align="left" variable="mongo.data.dir">
<spec txt="Data directory" size="25" set="$INSTALL_PATH\data" mustExist="false" create="true" />
</field>
</panel>
<panel order="1">
<!-- definition of a second panel -->
</panel>
</userInput>
You also need to include the userInputSpec.xml as a resource in your main installation file and add a UserInputPanel element for each panel that you define in userInputSpec.xml
Like this (in the <installation> element:
<resources>
<!-- other resources -->
<res id="userInputSpec.xml" src="userInputSpec.xml" />
</resources>
<panels>
<panel classname="HelloPanel"/>
<panel classname="InfoPanel"/>
<panel classname="LicencePanel"/>
<panel classname="TargetPanel"/>
<panel classname="TreePacksPanel"/>
<panel classname="UserInputPanel"/>
<panel classname="UserInputPanel"/>
<panel classname="InstallPanel"/>
<panel classname="ShortcutPanel"/>
<panel classname="FinishPanel"/>
</panels>
notice the double occurence of
I have two panels defined in my userInputSpec
Make sure that your UserInputPanels appear before InstallPanel because you have to get the variables from the user before copying your files.
This is just an example from my app. See the official documentation to get the idea of what the elements and attributes I used mean. There are many features connected with user input.