diff options
author | George Fraser <george@fivetran.com> | 2017-04-23 11:51:57 -0700 |
---|---|---|
committer | George Fraser <george@fivetran.com> | 2017-04-23 11:51:57 -0700 |
commit | 23409d69e369427b42c9a583ef963dbc83231168 (patch) | |
tree | 59ddf9afa2ee774afa9d0a091eb54fcab668a488 /README.md | |
parent | 3636ae93b38ae9c82707586ca61b65b3b11640f0 (diff) | |
download | java-language-server-23409d69e369427b42c9a583ef963dbc83231168.zip |
Update instructions
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 222 |
1 files changed, 29 insertions, 193 deletions
@@ -53,206 +53,49 @@ Requires that you have Java 8 installed on your system. ## Usage -## Using Maven pom.xml - -vscode-javac will look for a file named pom.xml in a parent directory of every open .java file. -vscode-javac will invoke maven in order to get the build classpath, so you need to be sure `mvn` is on your system path. - -## Using javaconfig.json - -The presence of a `javaconfig.json` file indicates that -its parent directory is the root of a Java module. -`javaconfig.json` looks like: - - [{ - "sourcePath": ["relative/path/to/source/root", ...], - "classPath": ["some-jar.jar", "some-dir"], - "classPathFile": "file-with-classpath-as-contents.txt", - "outputDirectory": "relative/path/to/output/root" - }, ... more configurations] - -The order is important: VSCode will use the first configuration with a sourcePath that matches the file you are editing. - -The classPathFile is contained in a separate file, in the format `entry.jar:another-entry.jar`. -This file is usually generated by a build tool like maven. - -### Examples - -### Maven - -pom.xml will be read automatically. - -### Maven (using javaconfig.json) - -You can configure maven to output the current classpath to a file, -classpath.txt, where Visual Studio Code will find it. - -#### javaconfig.json - -Set the source path, and get the class path from a file: - - [{ - "sourcePath": ["src/main/java"], - "classPathFile": "classpath.txt", - "outputDirectory": "target/classes" - }, { - "sourcePath": ["src/test/java"], - "classPath": ["target/classes"], - "classPathFile": "test-classpath.txt", - "outputDirectory": "target/test-classes" - }] - -#### pom.xml - -Configure maven to output `classpath.txt` - - <project ...> - ... - <build> - ... - <plugins> - ... - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-dependency-plugin</artifactId> - <version>2.9</version> - <executions> - <execution> - <id>classpath</id> - <phase>generate-sources</phase> - <goals> - <goal>build-classpath</goal> - </goals> - <configuration> - <includeScope>compile</includeScope> - <outputFile>classpath.txt</outputFile> - </configuration> - </execution> - <execution> - <id>test-classpath</id> - <phase>generate-sources</phase> - <goals> - <goal>build-classpath</goal> - </goals> - <configuration> - <includeScope>test</includeScope> - <outputFile>test-classpath.txt</outputFile> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - </project> - -#### .gitignore - -Ignore `classpath.txt`, since it will be different on every host - - classpath.txt - ... - -### Gradle - -Add this to your `build.gradle`: - -```gradle -task vscodeClasspathFile { - description 'Generates classpath file for the Visual Studio Code java plugin' - ext.destFile = file("$buildDir/classpath.txt") - outputs.file destFile - doLast { - def classpathString = configurations.compile.collect{ it.absolutePath }.join(File.pathSeparator) - if (!destFile.parentFile.exists()) { - destFile.parentFile.mkdirs() - } - assert destFile.parentFile.exists() - destFile.text = classpathString - } -} +VSCode will provide autocomplete and help text using: +* .java files anywhere in your workspace +* Java platform classes +* External dependencies specified using [settings](#Settings) -task vscodeJavaconfigFile(dependsOn: vscodeClasspathFile) { - description 'Generates javaconfig.json file for the Visual Studio Code java plugin' - - def relativePath = { File f -> - f.absolutePath - "${project.rootDir.absolutePath}/" - } - ext.destFile = file("javaconfig.json") - ext.config = [ - sourcePath: sourceSets.collect{ it.java.srcDirs }.flatten().collect{ relativePath(it) }, - classPathFile: relativePath(tasks.getByPath('vscodeClasspathFile').outputs.files.singleFile), - outputDirectory: relativePath(new File(buildDir, 'vscode-classes')) - ] - doLast { - def jsonContent = groovy.json.JsonOutput.toJson(ext.config) - destFile.text = groovy.json.JsonOutput.prettyPrint(jsonContent) - } -} +## Settings -task vscode(dependsOn: vscodeJavaconfigFile) { - description 'Generates config files for the Visual Studio Code java plugin' - group 'vscode' -} -``` +We recommend you set the following in your [workspace settings](https://code.visualstudio.com/docs/getstarted/settings) -Then run `gradlew vscode`. This will generate -* `javaconfig.json` -* `build/classpath.txt` +### java.externalDependencies -### Gradle Android build +If you are using external dependencies, you should specify them in `.vscode/settings.xml` in the following format: -For Android gradle project, put the above tasks in the `android` method of your `build.gradle`: -```gradle -android { - ... - // add the vscode tasks inside the android method - task vscodeClasspathFile { - ... +```json +{ + "java.externalDependencies": [ + // Maven format + "junit:junit:jar:4.12:test", + // Gradle-style format is also allowed + "junit:junit:4.12" + ] } ``` -Currently, the generated `classpath.txt` does not contain android platform library, e.g., `/opt/android-sdk-linux/platforms/android-23/android.jar`. You would need to add it manually. See issue #23. - -### SBT (Lightbend Activator) +Your build tools should be able to generate this list for you: -Add this to your `build.sbt` file to generate `classpath.txt` every time you execute the `compile` or `run` tasks. This has been tested with Lightbend Activator/sbt 0.13.11. +#### List maven dependencies: -```scala -val genClasspath = taskKey[String]("Generate classpath.txt for use with VS Code.") +```mvn dependency:list``` -genClasspath := { - val log = streams.value.log - val cp: Seq[File] = (dependencyClasspath in Compile).value.files - - val file = baseDirectory.value / "classpath.txt" - log.info("Writing classpath details to: " + file.getAbsolutePath) - IO.write(file, cp.map(_.getAbsolutePath).mkString(java.io.File.pathSeparator)) - file.getAbsolutePath -} +Look for entries like `[INFO] junit:junit:jar:4.11:test` -// Generate classpath.txt every time you compile or run the project -compile in Compile <<= (compile in Compile).dependsOn(genClasspath) -run in Compile <<= (run in Compile).dependsOn(genClasspath) +#### List gradle dependencies -``` +```gradle dependencies``` -#### javaconfig.json +Look for entries like `\--- junit:junit:4.+ -> 4.12` or `\--- org.hamcrest:hamcrest-core:1.3` +You may have to do a little reformatting. -Add this file and configure `sourcePath` and `outputDirectory` as needed: -```json -{ - "sourcePath": ["app"], - "classPathFile": "classpath.txt", - "outputDirectory": "target" -} -``` +## javaconfig.json is depecated -#### .gitignore - -Ignore `classpath.txt`, since it will be different on every host - - classpath.txt - ... +Configuration using a `javaconfig.json` file in your workspace is deprecated; +please switch to setting `java.externalDependencies` in `.vscode/settings.json` ## Directory structure @@ -296,15 +139,8 @@ then intercepts the data structures the Java compiler uses to represent source t The Java compiler isn't designed for incremental parsing and analysis. However, it is *extremely* fast, so recompiling a single file gives good performance, as long as we don't also recompile all of its dependencies. -We accomplish this by maintaining a single copy of the Java compiler in memory at all times. -When we want to recompile a file, -we clear that *one* file from the internal caches of the Java compiler, -and then rerun the compiler. - -### Multiple javaconfig.json - -If you have multiple javaconfig.json files in different subdirectories of your project, -the parent directory of each javaconfig.json will be treated as a separate java root. +We cache the .class files that are generated during compilation in a temporary folder, +and use those .class files instead of .java sources whenever they are up-to-date. ## Logs |