{"record":{"id":"503e6c4d12b73ee4","repo":"GoogleContainerTools/jib","slug":"cannot-apply-includes-excludes-on-single-file-copy","errorCode":null,"errorMessage":"Cannot apply includes/excludes on single file copy directives.","messagePattern":"Cannot apply includes/excludes on single file copy directives\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"jib-cli/src/main/java/com/google/cloud/tools/jib/cli/buildfile/Layers.java","lineNumber":87,"sourceCode":"        layerBuiler.setName(fileLayer.getName());\n        // layer properties\n        fileLayer.getProperties().ifPresent(filePropertiesStack::push);\n        for (CopySpec copySpec : ((FileLayerSpec) entry).getFiles()) {\n          // copy spec properties\n          copySpec.getProperties().ifPresent(filePropertiesStack::push);\n\n          // relativize all paths to the buildRoot location\n          Path rawSrc = copySpec.getSrc();\n          Path src = rawSrc.isAbsolute() ? rawSrc : buildRoot.resolve(rawSrc);\n          AbsoluteUnixPath dest = copySpec.getDest();\n\n          if (!Files.isDirectory(src) && !Files.isRegularFile(src)) {\n            throw new UnsupportedOperationException(\n                \"Cannot create FileLayers from non-file, non-directory: \" + src.toString());\n          }\n          if (Files.isRegularFile(src)) { // regular file\n            if (!copySpec.getExcludes().isEmpty() || !copySpec.getIncludes().isEmpty()) {\n              throw new UnsupportedOperationException(\n                  \"Cannot apply includes/excludes on single file copy directives.\");\n            }\n            layerBuiler.addEntry(\n                src,\n                copySpec.isDestEndsWithSlash() ? dest.resolve(src.getFileName()) : dest,\n                filePropertiesStack.getFilePermissions(),\n                filePropertiesStack.getModificationTime(),\n                filePropertiesStack.getOwnership());\n          } else if (Files.isDirectory(src)) { // directory\n            List<PathMatcher> excludes =\n                copySpec.getExcludes().stream()\n                    .map(Layers::toPathMatcher)\n                    .collect(Collectors.toList());\n            List<PathMatcher> includes =\n                copySpec.getIncludes().stream()\n                    .map(Layers::toPathMatcher)\n                    .collect(Collectors.toList());\n            try (Stream<Path> dirWalk = Files.walk(src)) {","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/GoogleContainerTools/jib/blob/fb949e2676afbbd7dd7a1ef61e20251931325654/jib-cli/src/main/java/com/google/cloud/tools/jib/cli/buildfile/Layers.java#L69-L105","documentation":"In Layers.toLayers, include/exclude filters are only supported for directory copy directives. When src is a single regular file and the copy spec declares any includes or excludes, the CLI throws UnsupportedOperationException with this message.","triggerScenarios":"A build file copy spec where src resolves to a single regular file and either 'excludes' or 'includes' is non-empty, e.g. {\"src\": \"app.jar\", \"dest\": \"/app\", \"excludes\": [\"*.tmp\"]}.","commonSituations":"Copy-pasting a directory copy spec and changing src to a file while leaving filter options in place.","solutions":["Remove the includes/excludes arrays from single-file copy directives.","Point src at the parent directory and use excludes/includes to narrow down to the desired file.","Restructure the spec so filtering applies only to directory sources."],"exampleFix":"// before\n{\"src\": \"app.jar\", \"dest\": \"/app\", \"excludes\": [\"*.tmp\"]}\n// after\n{\"src\": \"app.jar\", \"dest\": \"/app\"}","handlingStrategy":"validation","validationCode":"if (Files.isRegularFile(buildRoot.resolve(spec.getSrc()))\n    && (!spec.getExcludes().isEmpty() || !spec.getIncludes().isEmpty())) {\n  throw new IllegalStateException(\"includes/excludes not allowed on single-file copy: \" + spec.getSrc());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use includes/excludes with directory srcs","Remove filters when narrowing a spec to a single file","Review copy specs when changing src from directory to file"],"tags":["buildfile","validation","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"fb949e2676afbbd7dd7a1ef61e20251931325654","analyzedAt":"2026-09-06T14:04:09.491Z","contentChangedAt":"2026-09-06T14:04:09.491Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}