private static List<FileEntriesLayer> createLayersForLayeredSpringBootJar(
      Path localExplodedJarRoot) throws IOException {
    Path layerIndexPath = localExplodedJarRoot.resolve(BOOT_INF).resolve("layers.idx");
    Pattern layerNamePattern = Pattern.compile("- \"(.*)\":");
    Pattern layerEntryPattern = Pattern.compile("  - \"(.*)\"");
    Map<String, List<String>> layersMap = new LinkedHashMap<>();
    List<String> layerEntries = null;
    for (String line : Files.readAllLines(layerIndexPath, StandardCharsets.UTF_8)) {
      Matcher layerMatcher = layerNamePattern.matcher(line);
      Matcher entryMatcher = layerEntryPattern.matcher(line);
      if (layerMatcher.matches()) {
        layerEntries = new ArrayList<>();
        String layerName = layerMatcher.group(1);
        layersMap.put(layerName, layerEntries);
      } else if (entryMatcher.matches()) {
        Verify.verifyNotNull(layerEntries).add(entryMatcher.group(1));
      } else {
        throw new IllegalStateException(
            "Unable to parse BOOT-INF/layers.idx file in the JAR. Please check the format of layers.idx.");
      }
    }

    // If the layers.idx file looks like this, for example:
    // - "dependencies":
    //   - "BOOT-INF/lib/dependency1.jar"
    // - "application":
    //   - "BOOT-INF/classes/"
    //   - "META-INF/"
    // The predicate for the "dependencies" layer will be true if `path` is equal to
    // `BOOT-INF/lib/dependency1.jar` and the predicate for the "spring-boot-loader" layer will be
    // true if `path` is in either 'BOOT-INF/classes/` or `META-INF/`.
    List<FileEntriesLayer> layers = new ArrayList<>();
    for (Map.Entry<String, List<String>> entry : layersMap.entrySet()) {
      String layerName = entry.getKey();
      List<String> contents = entry.getValue();
      if (!contents.isEmpty()) {
        Predicate<Path> belongsToThisLayer =
            isInListedDirectoryOrIsSameFile(contents, localExplodedJarRoot);
        layers.add(
            ArtifactLayers.getDirectoryContentsAsLayer(
                layerName, localExplodedJarRoot, belongsToThisLayer, JarLayers.APP_ROOT));
      }
    }
    return layers;
  }
Creates layers as specified by the layers.idx file (located in the BOOT-INF/ directory of the
JAR).

@param localExplodedJarRoot Path to exploded JAR content root
@return list of {@link FileEntriesLayer}
@throws IOException when an IO error occurs
jib-cli/src/main/java/com/google/cloud/tools/jib/cli/jar/SpringBootExplodedProcessor.java