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

Configure language for JavaDoc generation #36

Open
henning-meinhardt opened this issue Jan 3, 2024 · 4 comments
Open

Configure language for JavaDoc generation #36

henning-meinhardt opened this issue Jan 3, 2024 · 4 comments

Comments

@henning-meinhardt
Copy link

henning-meinhardt commented Jan 3, 2024

Hi, i'm missing an option to specify the language code or locale to use when invoking XJC. The current behavior is that environment variable LANG decides which language is selected for generating the JavaDoc comments in the generated files. I would like to have this reproducible, so I'd like a way to define the language on my own.

You currently use
// Set encoding (work-around for https://github.com/gradle/gradle/issues/13843) forkOptions.environment("LANG", System.getenv("LANG") ?: "C.UTF-8")
which basically passes the LANG envionment variable down to the XJC worker. But unfortunately LANG is nothing you can control from within a gradle build script or the gradle.properties file. The environment variable can only be set outside of the gradle script, i.e. its value depends on the environment found when the script runs.

My suggestion is to provide a "language" or "locale" option in the XJCExtension that is honored in the forkOptions code above.

I'm using Gradle 8.5 by the way.

Kind regards
Henning

@henning-meinhardt
Copy link
Author

Hi, any suggestion for a workaround for this?

@wursthos
Copy link

wursthos commented May 2, 2024

Hey Henning,

I fixed this issue by simply putting the following option into my gradle build script:

xjc {
    /* This option makes sure generated javadoc is in english
     * as opposed to the locale of the current system. */
    options.add("-Duser.language=en")
    // ...
}

Worked like a charm.

@henning-meinhardt
Copy link
Author

henning-meinhardt commented May 13, 2024

Hi @wursthos , sorry for my late reply. I already tried that before and just did so again. It does not seem to work for me. The setting does not afffect the language of generated JavaDoc comments ;-( I'm using the latest version of the xjc-gradle-plugin and have the following defined in my gradle script:

xjc {
	String schemaPath = "webapp/WEB-INF/schema"
	xsdDir = layout.projectDirectory.dir (schemaPath)
	includes = [ "xxxxx.xsd" ]
	bindingFiles.setFrom (xsdDir.asFileTree.matching { include ("xxxxx.xjb") })
	outputJavaDir = file (generatedSourcesDir)
	useJakarta = true
	addCompilationDependencies = true
	options.add ("-Duser.language=es")
	options.add ("-Xannotate")
	options.add ("-Xfluent-api")
	options.add ("-Xcopyable")
}

The output does not change when adjusting the language. I made sure that the gradle task is not cached.

Are you sure to use the same plugin an I do and not jaxb2-maven-plugin which has dedicated support for the "-Duser.language" parameter (mojohaus/jaxb2-maven-plugin#9)?

@wursthos
Copy link

Hey @henning-meinhardt, you are right. I must have simultaneously changed my system locale and wrongly attributed the language change to the xjc option. Sorry about the confusion.

However, I found (and properly tested) a solution that actually works well enough for me.
I just added this line to my gradle.properties file:

org.gradle.jvmargs=-Duser.language=en -Duser.country=EN -Dfile.encoding=UTF-8

For the code to be regenerated in this language I had to run the clean task as well (./gradlew clean xjc ).

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

2 participants