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

How to pass environment Variables to MavenLauncher #4817

Closed
AryanMansani opened this issue Aug 1, 2022 · 5 comments · Fixed by #4830
Closed

How to pass environment Variables to MavenLauncher #4817

AryanMansani opened this issue Aug 1, 2022 · 5 comments · Fixed by #4830
Labels

Comments

@AryanMansani
Copy link

AryanMansani commented Aug 1, 2022

I have a project, where I am fetching code from a rep and then building a CtModel from it that repo.

Now in some project there are some environment variables in dependencies like -

<dependency>
<groupID>common-annotation</groupID>
<artifactID>common-annotation</artifactID>
<version>${revision}<version>
</dependency>

Here, revision is that variable, now when building a model, spoon gives an error.

Is there a way I can pass this variable to Maven Launcher or any other work around.

@I-Al-Istannen
Copy link
Collaborator

Probably not the best solution, but if they are present as environment variables, the spawned mvn process will inherit them. This means that revision=foo java YourProgram should work.

Setting that from inside your program is not really portable though. The maven launcher would need to expose an interface and use the addShellEnvironment method to pass that along to the invocation request.

@I-Al-Istannen
Copy link
Collaborator

Ah, I just thought of another slightly more realistic workaround:
You could edit the pom to add them to the properties section. Either using an XML library or some well-placed regular expressions :)

@AryanMansani
Copy link
Author

That's a really good idea, but for it, we need to beforehand identify either manually or by XML parser if this variable is not present in the properties, so for a single module it sounds okay but for a multi-modular project it sounds like a lot of work, is there a way we can automatically identify which variables are not present using any library?

@I-Al-Istannen
Copy link
Collaborator

You need to know which environment variables need to be set in any case. I guess we could also add that to the MavenLauncher API, setting environment variables sounds useful enough.

See #4830.

@I-Al-Istannen
Copy link
Collaborator

The new API you want to look at is setEnvironmentVariable in the MavenLauncher. Do let us know if this does not solve your issue @AryanMansani :)

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

Successfully merging a pull request may close this issue.

2 participants