Free tools Windows power users keep installed
One-click scans. No signup required.
The compile-time classpath gives the Java compiler access to dependencies needed to understand and compile source code. The runtime classpath gives the Java runtime access to dependencies needed to execute the compiled program. They often overlap, but they serve different phases and do not have to contain exactly the same dependencies.
What is the difference between compile-time and runtime classpaths?
When compiling Java source, javac must be able to find declarations for types the source uses, extends, or implements. The compile-time classpath is part of that lookup environment. When the program runs, the runtime needs access to the classes and other dependencies it requires to execute.
A dependency can therefore be available to compilation but absent at execution, or needed only when the program runs. A successful compile proves that the compiler found the types it needed; it does not, by itself, prove that the runtime can find every required class. Oracle documents the compiler’s role and classpath options in the Java SE 21 javac reference.
How Gradle separates the two classpaths
In Gradle’s Java Plugin, the main-source compileClasspath and runtimeClasspath are assembled from different dependency configurations. The compile classpath includes compileOnly and implementation; the runtime classpath includes runtimeOnly and implementation. This lets a project express whether a dependency is needed to compile, to run, or both. See Gradle’s Java Plugin documentation.
| Gradle configuration | Main compile classpath | Main runtime classpath | Typical meaning |
|---|---|---|---|
compileOnly |
Included | Omitted | Needed to compile, but supplied elsewhere or not needed at runtime. |
implementation |
Included | Included | Needed by the project’s implementation and available when it runs. |
runtimeOnly |
Omitted | Included | Needed during execution, but source does not need its types to compile. |
For example, a compile-time annotation API may be configured as compile-only when its implementation or relevant classes are provided through another mechanism. Confirm that the actual runtime environment supplies anything the program still needs; excluding a library from the runtime classpath is safe only when it is genuinely unnecessary there or is supplied elsewhere.
How Maven dependency scopes differ
Maven expresses dependency availability using scopes, not Gradle’s configuration names. The terms are related by purpose, but they are not interchangeable one-to-one. According to Maven’s dependency scope documentation, compile is the default and is available in all classpaths; runtime is needed for execution but not compilation; and test is for tests rather than non-test code.
Rank #2
| Maven scope | How to read it |
|---|---|
compile |
Default scope; available in all classpaths. |
runtime |
Needed at runtime, but not for compiling the project’s source. |
test |
Used for test code and test execution, not non-test code. |
Maven does not have a compileOnly scope. If you need compile-time-only behavior, do not assume a Gradle configuration name maps directly to a Maven scope; use the semantics supported by the Maven setup and verify what is published and available to consumers.
What library consumers receive
For a Gradle library using the Java Library Plugin, the choice between api and implementation affects consumers’ compile classpaths. An api dependency is exposed to consumers at compile time; an implementation dependency is not. Gradle recommends preferring implementation unless dependency types form part of the library’s public binary interface. A dependency is more likely to belong in api when its types appear in public parameters, fields, or supertypes. Details are in the Gradle Java Library Plugin documentation.
Tests have separate compile and runtime classpaths
Gradle separates the classpaths for test compilation and test execution as well: testCompileClasspath is used to compile test sources, while testRuntimeClasspath is used to run them. A test suite that compiles can still fail to start or execute if a required dependency is missing from its runtime classpath. The Java Plugin documentation describes these classpaths alongside the main-source classpaths.
How to diagnose a missing dependency
- Compilation fails to resolve a type: check whether the dependency containing that type is available to the compile classpath. A dependency declared as runtime-only will not provide types to source compilation.
- Compilation succeeds, but execution reports a missing class: check whether the needed dependency is on the runtime classpath or supplied by the execution environment. This follows from the different jobs of compiler lookup and runtime dependency availability.
- Tests compile but fail when launched: inspect the test runtime classpath, not only the test compile classpath.
- A downstream project cannot compile against your library’s public types: for a Gradle library, check whether a dependency whose types appear in the public API needs to be exposed with
apirather than kept asimplementation.
Setting the classpath with javac
For command-line compilation, Oracle documents --class-path, also written -classpath or -cp, as the option for locating user class files and annotation processors. An explicit classpath option overrides the CLASSPATH environment variable. The Oracle reference recommends using an explicit option when a classpath is required rather than setting that environment variable.
Rank #4
These classpath examples apply to classpath-based projects. Java’s module system adds another mechanism: modular applications may use --module-path and module resolution in addition to, or instead of, classpath lookup. Do not treat the classpath as a complete description of module-path behavior.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.

