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

use provider when setting jaxrs and annotation dependencies #1188

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ private static void createGenerateTask(

project.getDependencies().add("api", Dependencies.CONJURE_JAVA_LIB);
project.getDependencies().add("implementation", Dependencies.JETBRAINS_ANNOTATIONS);
boolean useJakarta = Dependencies.isJakartaPackages(extension.getJava());
project.getDependencies()
.add(
.addProvider(
"compileOnly",
useJakarta ? Dependencies.ANNOTATION_API_JAKARTA : Dependencies.ANNOTATION_API_JAVAX);
project.getProviders()
.provider(() -> Dependencies.getAnnotationApiDependency(extension::getJava)));

TaskProvider<WriteGitignoreTask> generateGitIgnore = ConjurePlugin.createWriteGitignoreTask(
project, "gitignoreConjure", project.getProjectDir(), ConjurePlugin.JAVA_GITIGNORE_CONTENTS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,23 +281,25 @@ private static void setupDialogueProject(Project project, Supplier<GeneratorOpti
}

private static void setupRetrofitProject(Project project, Supplier<GeneratorOptions> optionsSupplier) {
boolean useJakarta = Dependencies.isJakartaPackages(optionsSupplier.get());
project.getDependencies().add("api", "com.google.guava:guava");
project.getDependencies().add("api", "com.squareup.retrofit2:retrofit");
project.getDependencies()
.add(
.addProvider(
"compileOnly",
useJakarta ? Dependencies.ANNOTATION_API_JAKARTA : Dependencies.ANNOTATION_API_JAVAX);
project.getProviders()
.provider(() -> Dependencies.getAnnotationApiDependency(optionsSupplier)));
}

private static void setupJerseyProject(Project project, Supplier<GeneratorOptions> optionsSupplier) {
boolean useJakarta = Dependencies.isJakartaPackages(optionsSupplier.get());
project.getDependencies()
.add("api", useJakarta ? Dependencies.JAXRS_API_JAKARTA : Dependencies.JAXRS_API_JAVAX);
.addProvider(
"api",
project.getProviders().provider(() -> Dependencies.getJaxrsApiDependency(optionsSupplier)));
project.getDependencies()
.add(
.addProvider(
"compileOnly",
useJakarta ? Dependencies.ANNOTATION_API_JAKARTA : Dependencies.ANNOTATION_API_JAVAX);
project.getProviders()
.provider(() -> Dependencies.getAnnotationApiDependency(optionsSupplier)));
}

private static void setupUndertowProject(Project project, Supplier<GeneratorOptions> _optionsSupplier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.palantir.gradle.conjure;

import com.palantir.gradle.conjure.api.GeneratorOptions;
import java.util.function.Supplier;

final class Dependencies {

Expand All @@ -37,9 +38,17 @@ final class Dependencies {

private static final String JAKARTA_PACKAGES = "jakartaPackages";

static boolean isJakartaPackages(GeneratorOptions options) {
private static boolean isJakartaPackages(GeneratorOptions options) {
return options.has(JAKARTA_PACKAGES) && Boolean.TRUE.equals(options.get(JAKARTA_PACKAGES));
}

static String getJaxrsApiDependency(Supplier<GeneratorOptions> optionsSupplier) {
return isJakartaPackages(optionsSupplier.get()) ? JAXRS_API_JAKARTA : JAXRS_API_JAVAX;
}

static String getAnnotationApiDependency(Supplier<GeneratorOptions> optionsSupplier) {
return isJakartaPackages(optionsSupplier.get()) ? ANNOTATION_API_JAKARTA : ANNOTATION_API_JAVAX;
}

private Dependencies() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,38 @@ class ConjurePluginTest extends IntegrationSpec {
'peer' | ''
}

def 'featureFlag JakartaPackages can be enabled: #location'() {
file('api/build.gradle') << '''
conjure {
java {
jakartaPackages = true
}
}
'''.stripIndent()
updateSettings(prefix)

when:
runTasksSuccessfully(':api:compileConjureJersey')
ExecutionResult jerseyDependenciesResult = runTasksSuccessfully(prefixProject(prefix, 'api-jersey:dependencies'))

then:
String generatedServicePath = prefixPath(prefix, 'api-jersey/src/generated/java/test/test/api/TestServiceFoo.java')
fileExists(generatedServicePath)
File generatedService = new File(projectDir, generatedServicePath)
generatedService.text.contains("import jakarta.ws.rs")
!generatedService.text.contains("import javax.ws.rs")

jerseyDependenciesResult.standardOutput.contains("jakarta.ws.rs:jakarta.ws.rs-api")
jerseyDependenciesResult.standardOutput.contains("jakarta.annotation:jakarta.annotation-api")
!jerseyDependenciesResult.standardOutput.contains("javax.ws.rs:javax.ws.rs-api")
!jerseyDependenciesResult.standardOutput.contains("javax.annotation:javax.annotation-api")

where:
location | prefix
'sub' | 'api'
'peer' | ''
}

def 'typescript extension is respected: #location'() {
file('api/build.gradle') << '''
conjure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public final class TestVersions {
private TestVersions() {}

public static final String CONJURE = "4.30.0";
public static final String CONJURE_JAVA = "5.17.0";
public static final String CONJURE_JAVA = "6.57.0";
public static final String CONJURE_JAVA_DIALOG = "1.50.0";
public static final String CONJURE_PYTHON = "3.11.6";
public static final String CONJURE_TYPESCRIPT = "3.8.1";
Expand Down