From 4e597f2f60a673deb7189f04bfe653ac4af50fe0 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 8 Jan 2025 09:07:47 -0800 Subject: [PATCH] Skip module-info files in output_jar https://github.com/bazelbuild/rules_java/issues/260 PiperOrigin-RevId: 713312008 Change-Id: Ifaab4668abbf680912ded440e42bafe0cca7ec27 --- src/tools/singlejar/options.cc | 3 ++- src/tools/singlejar/options.h | 4 +++- src/tools/singlejar/output_jar.cc | 12 ++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/tools/singlejar/options.cc b/src/tools/singlejar/options.cc index 2728af3f69302b..5b8921f79461b3 100644 --- a/src/tools/singlejar/options.cc +++ b/src/tools/singlejar/options.cc @@ -60,7 +60,8 @@ bool Options::ParseToken(ArgTokenStream *tokens) { tokens->MatchAndSet("--hermetic_java_home", &hermetic_java_home) || tokens->MatchAndSet("--add_exports", &add_exports) || tokens->MatchAndSet("--add_opens", &add_opens) || - tokens->MatchAndSet("--output_jar_creator", &output_jar_creator)) { + tokens->MatchAndSet("--output_jar_creator", &output_jar_creator) || + tokens->MatchAndSet("--no_strip_module_info", &no_strip_module_info)) { return true; } else if (tokens->MatchAndSet("--build_info_file", &optarg)) { build_info_files.push_back(optarg); diff --git a/src/tools/singlejar/options.h b/src/tools/singlejar/options.h index 4527310075aeab..3f26977e74fe20 100644 --- a/src/tools/singlejar/options.h +++ b/src/tools/singlejar/options.h @@ -36,7 +36,8 @@ class Options { verbose(false), warn_duplicate_resources(false), check_desugar_deps(false), - multi_release(false) {} + multi_release(false), + no_strip_module_info(false) {} virtual ~Options() {} @@ -69,6 +70,7 @@ class Options { bool warn_duplicate_resources; bool check_desugar_deps; bool multi_release; + bool no_strip_module_info; std::string hermetic_java_home; std::vector add_exports; std::vector add_opens; diff --git a/src/tools/singlejar/output_jar.cc b/src/tools/singlejar/output_jar.cc index af02fdbf1f00ef..e6564e1a35f7df 100644 --- a/src/tools/singlejar/output_jar.cc +++ b/src/tools/singlejar/output_jar.cc @@ -24,6 +24,8 @@ #include #include +#include + #ifndef _WIN32 #include #else @@ -369,6 +371,16 @@ bool OutputJar::AddJar(int jar_path_index) { continue; } + // Skip module-info.class files + // Deploy jars are not modularized jars, and including module-infos from + // modularized dependencies doesn't work. See also b/204112761. + if (!options_->no_strip_module_info && + (!strncmp(file_name, "module-info.class", file_name_length) || + (begins_with(file_name, file_name_length, "META-INF/versions/") && + ends_with(file_name, file_name_length, "/module-info.class")))) { + continue; + } + bool include_entry = true; if (!options_->include_prefixes.empty()) { for (auto &prefix : options_->include_prefixes) {