diff --git a/buildSrc/src/main/java/com/linecorp/armeria/conventions/spring/SpringBuildUtil.java b/buildSrc/src/main/java/com/linecorp/armeria/conventions/spring/SpringBuildUtil.java index 6a4019fab45..14e56a182d0 100644 --- a/buildSrc/src/main/java/com/linecorp/armeria/conventions/spring/SpringBuildUtil.java +++ b/buildSrc/src/main/java/com/linecorp/armeria/conventions/spring/SpringBuildUtil.java @@ -96,14 +96,16 @@ private static Set sourceDirs(Project project, SourceSetType sourceSetType additionalSourceDirs = new String[] { "build/generated/sources/proto/test/grpc", "build/generated/sources/proto/test/java", - "gen-src/test/java" + "gen-src/test/java", + "gen-src/test/javaThrift" }; } else { assert sourceSetType == SourceSetType.MAIN; additionalSourceDirs = new String[] { "build/generated/sources/proto/main/grpc", "build/generated/sources/proto/main/java", - "gen-src/main/java" + "gen-src/main/java", + "gen-src/main/javaThrift" }; } for (String path : additionalSourceDirs) { diff --git a/gradle/scripts/lib/java-rpc-thrift.gradle b/gradle/scripts/lib/java-rpc-thrift.gradle index 31f4368aee9..90187ff9151 100644 --- a/gradle/scripts/lib/java-rpc-thrift.gradle +++ b/gradle/scripts/lib/java-rpc-thrift.gradle @@ -50,7 +50,10 @@ configure(projectsWithFlags('java')) { includeDirs = [includeDirs] } includeDirs = project.files(includeDirs) - def javaOutputDir = project.file("${project.ext.genSrcDir}/${scope}/java") + def javaOutputDir = project.file("${project.ext.genSrcDir}/${scope}/javaThrift") + if (!sourceSet.java.srcDirs.contains(javaOutputDir)) { + sourceSet.java.srcDir javaOutputDir + } def jsonOutputDir = project.file("${project.ext.genSrcDir}/${scope}/resources") task.configure { // configure inputs and outputs diff --git a/gradle/scripts/lib/java-shade.gradle b/gradle/scripts/lib/java-shade.gradle index 140de5873fe..7f0a3810e0a 100644 --- a/gradle/scripts/lib/java-shade.gradle +++ b/gradle/scripts/lib/java-shade.gradle @@ -371,7 +371,13 @@ private void configureShadowTask(Project project, ShadowJar task, boolean isMain relocations.each { props -> - task.relocate props['from'], props['to'] + logger.debug("[${project.name}] Relocating ${props['name']} from ${props['from']} to ${props['to']} " + + "in ${isMain ? 'main' : 'test'}") + task.relocate(props['from'], props['to']) { + exclude { + return isGenerated(project, it.path, isMain) + } + } } dependencies { @@ -402,6 +408,34 @@ private void configureShadowTask(Project project, ShadowJar task, boolean isMain } } +boolean isGenerated(Project project, String path, boolean isMain) { + if (path.endsWith("package-info.class")) { + return false + } + if (!path.endsWith('.class')) { + return false + } + // Remove the .class extension. + def className = path.substring(0, path.length() - 6) + // Remove the inner class part. + def topLevelClassName = className.split('\\$')[0] + + def javaSourcePath = "${topLevelClassName}.java" + def scope = isMain ? 'main' : 'test' + def thriftGenSrcDir = "${project.ext.genSrcDir}/${scope}/javaThrift" + def grpcGenSrcDir = "${project.buildDir}/generated/sources/proto/${scope}/grpc" + def protoGenSrcDir = "${project.buildDir}/generated/sources/proto/${scope}/java" + + // Check if the source file exists in any of the generated source directories. + if (new File("${thriftGenSrcDir}/${javaSourcePath}").exists() || + new File("${grpcGenSrcDir}/${javaSourcePath}").exists() || + new File("${protoGenSrcDir}/${javaSourcePath}").exists()) { + logger.debug("[${project.name}] Excluding generated class from shading: ${path}") + return true + } + return false +} + /** * Finds the dependencies of {@code project} recursively and adds the found dependencies to * the configuration named as {@code 'shadedJarTestImplementation'}.