@@ -194,18 +194,39 @@ public JavaAspectsInfo(ParsedBepOutput aspectsBuildResult, BazelWorkspace bazelW
194194 "Unable to compute target label for runtime jar '{}'. Please check if the rule producing the jar is adding the Target-Label to the jar manifest!" ,
195195 classJar );
196196 }
197- targetLabel = Label .create (format ("@_unknown_jar_//:%s" , sanitizePathForLabel (classJar .getRelativePath ())));
198- } else if (!targetLabel .isExternal ()
199- && !bazelWorkspace .getBazelPackage (new BazelLabel (targetLabel )).exists ()) {
200- // possibly an external jar produced within an external repo
201- // see https://github.com/eclipseguru/bazel-eclipse/issues/34
202- if (LOG .isDebugEnabled ()) {
203- LOG .debug (
204- "The target '{}' of the runtime JAR file '{}' does not exist in the workspace." ,
205- targetLabel ,
206- classJar );
197+ targetLabel = Label .create (
198+ format ("@_unknown_jar_//:%s" , sanitizePathForLabel (classJar .getRelativePath ())));
199+ } else if (!targetLabel .isExternal ()) {
200+ // Use toArtifactLocation to determine if JAR is physically in external repository
201+ var artifactLocation = toArtifactLocation (localJar );
202+
203+ if (artifactLocation .isExternal ()) {
204+ // JAR is in external repository but has non-external target label
205+ // This indicates incorrect manifest (e.g., //3rdparty/java instead of @maven//:...)
206+ // See https://github.com/eclipseguru/bazel-eclipse/issues/48
207+ if (LOG .isWarnEnabled ()) {
208+ LOG .warn (
209+ "Manifest label mismatch: JAR '{}' is in external repository but has non-external target label '{}'. "
210+ + "This indicates an incorrect manifest. The JAR will be indexed as unknown. "
211+ + "Consider fixing the build configuration to write correct target labels." ,
212+ classJar ,
213+ targetLabel );
214+ }
215+ targetLabel = Label .create (
216+ format ("@_unknown_jar_//:%s" , sanitizePathForLabel (classJar .getRelativePath ())));
217+ } else if (!bazelWorkspace .getBazelPackage (new BazelLabel (targetLabel )).exists ()) {
218+ // Local JAR but package doesn't exist
219+ // possibly an external jar produced within an external repo
220+ // see https://github.com/eclipseguru/bazel-eclipse/issues/34
221+ if (LOG .isDebugEnabled ()) {
222+ LOG .debug (
223+ "The target '{}' of the runtime JAR file '{}' does not exist in the workspace." ,
224+ targetLabel ,
225+ classJar );
226+ }
227+ targetLabel = Label .create (
228+ format ("@_unknown_jar_//:%s" , sanitizePathForLabel (classJar .getRelativePath ())));
207229 }
208- targetLabel = Label .create (format ("@_unknown_jar_//:%s" , sanitizePathForLabel (classJar .getRelativePath ())));
209230 }
210231
211232 var builder = LibraryArtifact .builder ();
@@ -310,9 +331,18 @@ private ArtifactLocation toArtifactLocation(LocalFileArtifact localJar) {
310331 localJarExecutionRootRelativePath ));
311332 }
312333
313- return ExecutionPathHelper .parse (
314- workspaceRoot ,
315- BazelBuildSystemProvider .BAZEL ,
316- fromPath (localJarExecutionRootRelativePath ).toString ());
334+ var executionRootRelativePathString = fromPath (localJarExecutionRootRelativePath ).toString ();
335+ var artifactLocation = ExecutionPathHelper
336+ .parse (workspaceRoot , BazelBuildSystemProvider .BAZEL , executionRootRelativePathString );
337+
338+ // ExecutionPathHelper.parse() only detects external artifacts when the path starts with "external/"
339+ // However, external JARs can also be in "bazel-out/<config>/bin/external/..." paths
340+ // Fix the isExternal flag if the path contains "/external/" but wasn't detected
341+ if (!artifactLocation .isExternal () && executionRootRelativePathString .contains ("/external/" )) {
342+ // Path contains "/external/" but wasn't detected as external - correct this
343+ return ArtifactLocation .Builder .copy (artifactLocation ).setIsExternal (true ).build ();
344+ }
345+
346+ return artifactLocation ;
317347 }
318348}
0 commit comments