Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document on how to add the jspecify dependency: Maven and Gradle #503

Open
sdavids opened this issue Mar 29, 2024 · 3 comments
Open

Document on how to add the jspecify dependency: Maven and Gradle #503

sdavids opened this issue Mar 29, 2024 · 3 comments

Comments

@sdavids
Copy link

sdavids commented Mar 29, 2024

Please add a section to the README similar to the one at @API Guardian.

You might also want to add it to either Start Here and/or Nullness User Guide.

Maven

<dependency>
  <groupId>org.jspecify</groupId>
  <artifactId>jspecify</artifactId>
  <version>0.3.0</version>
</dependency>

or

<dependency>
  <groupId>org.jspecify</groupId>
  <artifactId>jspecify</artifactId>
  <version>0.3.0</version>
  <scope>provided</scope>
</dependency>

Related: #389

Gradle

The Java Library plugin configurations

dependencies {
  api("org.jspecify:jspecify:0.3.0")
}

or

dependencies {
  implementation("org.jspecify:jspecify:0.3.0")
}

or

dependencies {
  compileOnlyApi("org.jspecify:jspecify:0.3.0")
}

or

dependencies {
  compileOnly("org.jspecify:jspecify:0.3.0")
}

If it is not compileOnlyApi you might want to add a link to an appropriate FAQ entry.

@tbroyer
Copy link

tbroyer commented Mar 29, 2024

Fwiw, because JSpecify can be used at runtime, I'd favor api in Gradle (and not-provided, not-optional in Maven). Those who don't use the annotations at runtime, and don't want to ship the JSpecify JAR in their application can safely exclude it from their deliverables, but the rule should be that it's "included by default".
(it is an anti-pattern to mark annotation dependencies as compileOnly or compileOnlyApi, it depends on the annotation retention: source → compileOnly, class → compileOnlyApi, runtime → api; in Maven: source → provided/optional is the closest you can do, class or runtime → compile)

@GregDThomas
Copy link

GregDThomas commented Mar 29, 2024

I'd favor api in Gradle

For libraries, yes. For applications, I would think compileOnly would be fine, no?

@tbroyer
Copy link

tbroyer commented Mar 29, 2024

If you're using the java (or application) plugin in Gradle, rather than java-library, for an application, then you don't have api and compileOnlyApi, and you only have to choose between implementation and compileOnly, which is what I hinted above: if you don't use the annotations at runtime, and don't want to ship the JSpecify JAR in your application, you can safely use compileOnly, otherwise use implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants