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

maven buildpack environment configuration #508

Merged
merged 3 commits into from
Jun 13, 2023
Merged
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
2 changes: 2 additions & 0 deletions buildpacks/maven/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

* This buildpack now declares to be compatible with the `*` stack. While the buildpack cannot guarantee it works with any stack conceivable, it should be compatible with some stacks that are not maintained by Heroku. Use of this buildpack on such stacks is unsupported. ([#498](https://github.com/heroku/buildpacks-jvm/pull/498))
hone marked this conversation as resolved.
Show resolved Hide resolved
* Allow `JAVA_HOME` to be set by user or operator via `<platform>/env`. ([#508](https://github.com/heroku/buildpacks-jvm/pull/508))
* `MAVEN_SETTINGS_PATH`, `MAVEN_ESTTINGS_URL`, `MAVEN_CUSTOM_GOALS`, and `MAVEN_CUSTOM_OPTS` can be set by a previous buildpack. ([#508](https://github.com/heroku/buildpacks-jvm/pull/508))

## [1.0.4] 2023/05/11

Expand Down
23 changes: 14 additions & 9 deletions buildpacks/maven/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ impl Buildpack for MavenBuildpack {

#[allow(clippy::too_many_lines)]
fn build(&self, context: BuildContext<Self>) -> libcnb::Result<BuildResult, Self::Error> {
let mut current_or_platform_env = Env::from_current();
for (key, value) in context.platform.env().iter() {
current_or_platform_env.insert(key, value);
}

let maven_repository_layer =
context.handle_layer(layer_name!("repository"), MavenRepositoryLayer)?;

Expand All @@ -122,7 +127,7 @@ impl Buildpack for MavenBuildpack {

log_header("Installing Maven");

let (mvn_executable, mvn_env) = match maven_mode {
let (mvn_executable, mut mvn_env) = match maven_mode {
Mode::UseWrapper => {
log_info("Maven wrapper detected, skipping installation.");

Expand Down Expand Up @@ -179,10 +184,11 @@ impl Buildpack for MavenBuildpack {
)
}
};
if let Some(java_home) = current_or_platform_env.get("JAVA_HOME") {
mvn_env.insert("JAVA_HOME", java_home);
}

let maven_goals = context
.platform
.env()
let maven_goals = current_or_platform_env
.get("MAVEN_CUSTOM_GOALS")
.map_or_else(
|| Ok(default_maven_goals()),
Expand All @@ -192,9 +198,7 @@ impl Buildpack for MavenBuildpack {
},
)?;

let mut maven_options = context
.platform
.env()
let mut maven_options = current_or_platform_env
.get("MAVEN_CUSTOM_OPTS")
.map_or_else(
|| Ok(default_maven_opts()),
Expand All @@ -207,8 +211,9 @@ impl Buildpack for MavenBuildpack {
},
)?;

let settings_xml_path = resolve_settings_xml_path(&context.app_dir, context.platform.env())
.map_err(MavenBuildpackError::SettingsError)?;
let settings_xml_path =
resolve_settings_xml_path(&context.app_dir, &current_or_platform_env)
.map_err(MavenBuildpackError::SettingsError)?;

if let Some(settings_xml_path) = settings_xml_path {
maven_options.push(String::from("-s"));
Expand Down