-
Notifications
You must be signed in to change notification settings - Fork 10
versionsProvidingConfiguration change and ExportAllExcludes #207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,7 @@ public abstract class ExtraJavaModuleInfoPluginExtension { | |
|
|
||
| public abstract Property<Boolean> getDeriveAutomaticModuleNamesFromFileNames(); | ||
|
|
||
| public abstract Property<String> getVersionsProvidingConfiguration(); | ||
| public abstract Property<Configuration> getVersionsProvidingConfiguration(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should change this. If I understand your reasoning correctly, this actually makes the situation worse. The code at the moment always takes the To solve the warning in you project, you should never do something like this: Note: if you turn on Instead, you should make the // main/platform/build.gradle.kts
val consistentResolutionAttribute = Attribute.of("consistent-resolution", String::class.java)
configurations.create("allDependencies") {
isCanBeResolved = false
...
attributes { attribute(consistentResolutionAttribute, "global") }
}// main/project/build.gradle.kts
val consistentResolutionAttribute = Attribute.of("consistent-resolution", String::class.java)
val allDependenciesPath = configurations.create("allDependenciesPath")) {
isCanBeConsumed = false
attributes { attribute(consistentResolutionAttribute, "global") }
}
dependencies {
allDependenciesPath(project(":platform"))
}
extraJavaModuleInfo {
versionsProvidingConfiguration = "allDependenciesPath"
}This is a bit tricky, but I don't have a more compact solution. And because it is quite individual in different project setups, and cross-cutting subprojects, I don't have a good idea for features in this plugin to make it easier atm. |
||
|
|
||
| /** | ||
| * Add full module information for a given Jar file. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -333,6 +333,10 @@ private void addModuleDescriptor(File originalJar, File moduleJar, ModuleInfo mo | |
| packages); | ||
| mergeJars(moduleInfo, outputStream, providers, packages); | ||
| outputStream.putNextEntry(newReproducibleEntry("module-info.class")); | ||
|
|
||
| if (moduleInfo.exportAllPackages) { | ||
| moduleInfo.exportAllPackagesExceptions.forEach(it -> packages.remove(packageToPath(it))); | ||
| } | ||
| outputStream.write(addModuleInfo( | ||
| moduleInfo, | ||
| providers, | ||
|
|
@@ -390,7 +394,7 @@ private byte[] copyAndExtractProviders( | |
| String packagePath = | ||
| i > 0 ? mrJarMatcher.matches() ? mrJarMatcher.group(1) : entryName.substring(0, i) : ""; | ||
|
|
||
| if (!removedPackages.contains(packagePath.replace('/', '.'))) { | ||
| if (!removedPackages.contains(pathToPackage(packagePath))) { | ||
| if (entryName.endsWith(".class") && !packagePath.isEmpty()) { | ||
| packages.add(packagePath); | ||
| } | ||
|
|
@@ -462,6 +466,24 @@ public void visitEnd() { | |
| return classWriter.toByteArray(); | ||
| } | ||
|
|
||
| /** | ||
| * Convert a Java package name to a path | ||
| * @param packageName The package name | ||
| * @return The package name converted to a path | ||
| */ | ||
| private static String packageToPath(String packageName) { | ||
| return packageName.replace('.', '/'); | ||
| } | ||
|
|
||
| /** | ||
| * Convert a path to a Java package name | ||
| * @param path The path | ||
| * @return The path converted to a package name | ||
| */ | ||
| private static String pathToPackage(String path) { | ||
| return path.replace('/', '.'); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ Thanks for introducing these methods! |
||
|
|
||
| private void addModuleInfoEntires( | ||
| ModuleInfo moduleInfo, | ||
| Map<String, List<String>> providers, | ||
|
|
@@ -473,13 +495,13 @@ private void addModuleInfoEntires( | |
| for (Map.Entry<String, Set<String>> entry : moduleInfo.exports.entrySet()) { | ||
| String packageName = entry.getKey(); | ||
| Set<String> modules = entry.getValue(); | ||
| moduleVisitor.visitExport(packageName.replace('.', '/'), 0, modules.toArray(new String[0])); | ||
| moduleVisitor.visitExport(packageToPath(packageName), 0, modules.toArray(new String[0])); | ||
| } | ||
|
|
||
| for (Map.Entry<String, Set<String>> entry : moduleInfo.opens.entrySet()) { | ||
| String packageName = entry.getKey(); | ||
| Set<String> modules = entry.getValue(); | ||
| moduleVisitor.visitOpen(packageName.replace('.', '/'), 0, modules.toArray(new String[0])); | ||
| moduleVisitor.visitOpen(packageToPath(packageName), 0, modules.toArray(new String[0])); | ||
| } | ||
|
|
||
| if (moduleInfo.requireAllDefinedDependencies) { | ||
|
|
@@ -524,7 +546,7 @@ private void addModuleInfoEntires( | |
| moduleVisitor.visitRequire(requireName, Opcodes.ACC_STATIC_PHASE | Opcodes.ACC_TRANSITIVE, null); | ||
| } | ||
| for (String usesName : moduleInfo.uses) { | ||
| moduleVisitor.visitUse(usesName.replace('.', '/')); | ||
| moduleVisitor.visitUse(packageToPath(usesName)); | ||
| } | ||
| for (Map.Entry<String, List<String>> entry : providers.entrySet()) { | ||
| String name = entry.getKey(); | ||
|
|
@@ -539,9 +561,9 @@ private void addModuleInfoEntires( | |
| } | ||
| if (!implementations.isEmpty()) { | ||
| moduleVisitor.visitProvide( | ||
| name.replace('.', '/'), | ||
| packageToPath(name), | ||
| implementations.stream() | ||
| .map(impl -> impl.replace('.', '/')) | ||
| .map(ExtraJavaModuleInfoTransform::packageToPath) | ||
| .toArray(String[]::new)); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -177,6 +177,69 @@ class EdgeCasesFunctionalTest extends Specification { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run().task(':run').outcome == TaskOutcome.SUCCESS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def "can automatically export all packages except specified of a legacy Jar"() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| given: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| file("src/main/java/org/gradle/sample/app/Main.java") << """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| package org.gradle.sample.app; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import javax.json.JsonString; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import javax.json.JsonValue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public class Main { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static void main(String[] args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| JsonString jsonString = new JsonString() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public boolean equals(Object obj) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public CharSequence getChars() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public String getString() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public int hashCode() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public JsonValue.ValueType getValueType() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| file("src/main/java/module-info.java") << """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| module org.gradle.sample.app { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exports org.gradle.sample.app; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| requires org.glassfish.java.json; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| requires java.json; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| buildFile << """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dependencies { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| implementation("org.glassfish:jakarta.json:1.1.6") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| implementation("jakarta.json:jakarta.json-api:1.1.6") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| extraJavaModuleInfo { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| module("org.glassfish:jakarta.json", "org.glassfish.java.json") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exportAllPackagesExcept("javax.json", "javax.json.spi", "javax.json.stream") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| overrideModuleName() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| knownModule("jakarta.json:jakarta.json-api", "java.json") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def result = failRun() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result.output.matches(/(?s).*Package javax\.json[.a-z]* in both.*/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+215
to
+240
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for adding a test. Right now it does not seem to test the new feature, though. The split-package error will always occur no matter if the packages are exported or not. I suggest the following adjustment
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def "deriveAutomaticModuleNamesFromFileNames produces a build time error for invalid module names"() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| given: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| buildFile << """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍