Skip to content

Commit 23409d6

Browse files
committed
Update instructions
1 parent 3636ae9 commit 23409d6

1 file changed

Lines changed: 29 additions & 193 deletions

File tree

‎README.md‎

Lines changed: 29 additions & 193 deletions
Original file line numberDiff line numberDiff line change
@@ -53,206 +53,49 @@ Requires that you have Java 8 installed on your system.
5353

5454
## Usage
5555

56-
## Using Maven pom.xml
57-
58-
vscode-javac will look for a file named pom.xml in a parent directory of every open .java file.
59-
vscode-javac will invoke maven in order to get the build classpath, so you need to be sure `mvn` is on your system path.
60-
61-
## Using javaconfig.json
62-
63-
The presence of a `javaconfig.json` file indicates that
64-
its parent directory is the root of a Java module.
65-
`javaconfig.json` looks like:
66-
67-
[{
68-
"sourcePath": ["relative/path/to/source/root", ...],
69-
"classPath": ["some-jar.jar", "some-dir"],
70-
"classPathFile": "file-with-classpath-as-contents.txt",
71-
"outputDirectory": "relative/path/to/output/root"
72-
}, ... more configurations]
73-
74-
The order is important: VSCode will use the first configuration with a sourcePath that matches the file you are editing.
75-
76-
The classPathFile is contained in a separate file, in the format `entry.jar:another-entry.jar`.
77-
This file is usually generated by a build tool like maven.
78-
79-
### Examples
80-
81-
### Maven
82-
83-
pom.xml will be read automatically.
84-
85-
### Maven (using javaconfig.json)
86-
87-
You can configure maven to output the current classpath to a file,
88-
classpath.txt, where Visual Studio Code will find it.
89-
90-
#### javaconfig.json
91-
92-
Set the source path, and get the class path from a file:
93-
94-
[{
95-
"sourcePath": ["src/main/java"],
96-
"classPathFile": "classpath.txt",
97-
"outputDirectory": "target/classes"
98-
}, {
99-
"sourcePath": ["src/test/java"],
100-
"classPath": ["target/classes"],
101-
"classPathFile": "test-classpath.txt",
102-
"outputDirectory": "target/test-classes"
103-
}]
104-
105-
#### pom.xml
106-
107-
Configure maven to output `classpath.txt`
108-
109-
<project ...>
110-
...
111-
<build>
112-
...
113-
<plugins>
114-
...
115-
<plugin>
116-
<groupId>org.apache.maven.plugins</groupId>
117-
<artifactId>maven-dependency-plugin</artifactId>
118-
<version>2.9</version>
119-
<executions>
120-
<execution>
121-
<id>classpath</id>
122-
<phase>generate-sources</phase>
123-
<goals>
124-
<goal>build-classpath</goal>
125-
</goals>
126-
<configuration>
127-
<includeScope>compile</includeScope>
128-
<outputFile>classpath.txt</outputFile>
129-
</configuration>
130-
</execution>
131-
<execution>
132-
<id>test-classpath</id>
133-
<phase>generate-sources</phase>
134-
<goals>
135-
<goal>build-classpath</goal>
136-
</goals>
137-
<configuration>
138-
<includeScope>test</includeScope>
139-
<outputFile>test-classpath.txt</outputFile>
140-
</configuration>
141-
</execution>
142-
</executions>
143-
</plugin>
144-
</plugins>
145-
</build>
146-
</project>
147-
148-
#### .gitignore
149-
150-
Ignore `classpath.txt`, since it will be different on every host
151-
152-
classpath.txt
153-
...
154-
155-
### Gradle
156-
157-
Add this to your `build.gradle`:
158-
159-
```gradle
160-
task vscodeClasspathFile {
161-
description 'Generates classpath file for the Visual Studio Code java plugin'
162-
ext.destFile = file("$buildDir/classpath.txt")
163-
outputs.file destFile
164-
doLast {
165-
def classpathString = configurations.compile.collect{ it.absolutePath }.join(File.pathSeparator)
166-
if (!destFile.parentFile.exists()) {
167-
destFile.parentFile.mkdirs()
168-
}
169-
assert destFile.parentFile.exists()
170-
destFile.text = classpathString
171-
}
172-
}
56+
VSCode will provide autocomplete and help text using:
57+
* .java files anywhere in your workspace
58+
* Java platform classes
59+
* External dependencies specified using [settings](#Settings)
17360

174-
task vscodeJavaconfigFile(dependsOn: vscodeClasspathFile) {
175-
description 'Generates javaconfig.json file for the Visual Studio Code java plugin'
176-
177-
def relativePath = { File f ->
178-
f.absolutePath - "${project.rootDir.absolutePath}/"
179-
}
180-
ext.destFile = file("javaconfig.json")
181-
ext.config = [
182-
sourcePath: sourceSets.collect{ it.java.srcDirs }.flatten().collect{ relativePath(it) },
183-
classPathFile: relativePath(tasks.getByPath('vscodeClasspathFile').outputs.files.singleFile),
184-
outputDirectory: relativePath(new File(buildDir, 'vscode-classes'))
185-
]
186-
doLast {
187-
def jsonContent = groovy.json.JsonOutput.toJson(ext.config)
188-
destFile.text = groovy.json.JsonOutput.prettyPrint(jsonContent)
189-
}
190-
}
61+
## Settings
19162

192-
task vscode(dependsOn: vscodeJavaconfigFile) {
193-
description 'Generates config files for the Visual Studio Code java plugin'
194-
group 'vscode'
195-
}
196-
```
63+
We recommend you set the following in your [workspace settings](https://code.visualstudio.com/docs/getstarted/settings)
19764

198-
Then run `gradlew vscode`. This will generate
199-
* `javaconfig.json`
200-
* `build/classpath.txt`
65+
### java.externalDependencies
20166

202-
### Gradle Android build
67+
If you are using external dependencies, you should specify them in `.vscode/settings.xml` in the following format:
20368

204-
For Android gradle project, put the above tasks in the `android` method of your `build.gradle`:
205-
```gradle
206-
android {
207-
...
208-
// add the vscode tasks inside the android method
209-
task vscodeClasspathFile {
210-
...
69+
```json
70+
{
71+
"java.externalDependencies": [
72+
// Maven format
73+
"junit:junit:jar:4.12:test",
74+
// Gradle-style format is also allowed
75+
"junit:junit:4.12"
76+
]
21177
}
21278
```
21379

214-
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.
215-
216-
### SBT (Lightbend Activator)
80+
Your build tools should be able to generate this list for you:
21781

218-
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.
82+
#### List maven dependencies:
21983

220-
```scala
221-
val genClasspath = taskKey[String]("Generate classpath.txt for use with VS Code.")
84+
```mvn dependency:list```
22285

223-
genClasspath := {
224-
val log = streams.value.log
225-
val cp: Seq[File] = (dependencyClasspath in Compile).value.files
226-
227-
val file = baseDirectory.value / "classpath.txt"
228-
log.info("Writing classpath details to: " + file.getAbsolutePath)
229-
IO.write(file, cp.map(_.getAbsolutePath).mkString(java.io.File.pathSeparator))
230-
file.getAbsolutePath
231-
}
86+
Look for entries like `[INFO] junit:junit:jar:4.11:test`
23287

233-
// Generate classpath.txt every time you compile or run the project
234-
compile in Compile <<= (compile in Compile).dependsOn(genClasspath)
235-
run in Compile <<= (run in Compile).dependsOn(genClasspath)
88+
#### List gradle dependencies
23689

237-
```
90+
```gradle dependencies```
23891

239-
#### javaconfig.json
92+
Look for entries like `\--- junit:junit:4.+ -> 4.12` or `\--- org.hamcrest:hamcrest-core:1.3`
93+
You may have to do a little reformatting.
24094

241-
Add this file and configure `sourcePath` and `outputDirectory` as needed:
242-
```json
243-
{
244-
"sourcePath": ["app"],
245-
"classPathFile": "classpath.txt",
246-
"outputDirectory": "target"
247-
}
248-
```
95+
## javaconfig.json is depecated
24996

250-
#### .gitignore
251-
252-
Ignore `classpath.txt`, since it will be different on every host
253-
254-
classpath.txt
255-
...
97+
Configuration using a `javaconfig.json` file in your workspace is deprecated;
98+
please switch to setting `java.externalDependencies` in `.vscode/settings.json`
25699

257100
## Directory structure
258101

@@ -296,15 +139,8 @@ then intercepts the data structures the Java compiler uses to represent source t
296139
The Java compiler isn't designed for incremental parsing and analysis.
297140
However, it is *extremely* fast, so recompiling a single file gives good performance,
298141
as long as we don't also recompile all of its dependencies.
299-
We accomplish this by maintaining a single copy of the Java compiler in memory at all times.
300-
When we want to recompile a file,
301-
we clear that *one* file from the internal caches of the Java compiler,
302-
and then rerun the compiler.
303-
304-
### Multiple javaconfig.json
305-
306-
If you have multiple javaconfig.json files in different subdirectories of your project,
307-
the parent directory of each javaconfig.json will be treated as a separate java root.
142+
We cache the .class files that are generated during compilation in a temporary folder,
143+
and use those .class files instead of .java sources whenever they are up-to-date.
308144

309145
## Logs
310146

0 commit comments

Comments
 (0)