Skip to content

Commit d7e960f

Browse files
Eik0freshFKHalspaun42panphil
committed
[BUILD] TODO better message which explains the change more deeply
[BUILD] Separate transitive dependencies in core so that the core can act as a dependency-container without leaking it's own (non-transitive) dependencies into the classpaths of the packages importing it while still providing the transitive dependencies that are needed by those packages. This is implemented by creating the two new configurations "bundle" and "bundleApi" which replace the previously used "releaseDep". Dependencies of the "bundle"-configuration gets extend from the "implementation"-configuration (by the gradle-java-plugin) which is not transitive and therefore it's dependencies are only visible to the core package itself while the dependencies in "bundleApi" (which the corresponding "api"-config extends from) can be used by all packages that import the core. Extension in the context of configurations means that that all the dependencies in the "bundle"-config also get added to the "implementation"-config. This solution has the advantage to other solutions (e.g. creating a new OSGI package) that the complexity of the build system is not significantly increased and no versioning of any additional OSGI packages needs to be considered. This solution was proposed and explained to the authors by @m273d15 following the PR saros-project#1118. (saros-project#1118) Co-authored-by: FKHals <[email protected]> Co-authored-by: paun42 <[email protected]> Co-authored-by: panphil <[email protected]>
1 parent 2b64170 commit d7e960f

File tree

5 files changed

+75
-25
lines changed

5 files changed

+75
-25
lines changed

build.gradle.kts

+10
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ subprojects {
5454
create("releaseDep") { // contains all dependencies which has to be included into the release jar/zip
5555
isTransitive = false // avoid that the whole dependency tree is released
5656
}
57+
create("bundle") { // contains all which are used by core
58+
isTransitive = false // avoid that the whole dependency tree is released
59+
}
60+
create("bundleApi") { // contains all dependencies which are used by all java subprojects
61+
isTransitive = false // avoid that the whole dependency tree is released
62+
}
5763
}
5864

5965
configure<PmdExtension> {
@@ -110,6 +116,8 @@ subprojects {
110116
register("generateLib", Copy::class) {
111117
into("${project.projectDir}/lib")
112118
from(projectToConf.configurations.getByName("releaseDep"))
119+
from(projectToConf.configurations.getByName("bundle"))
120+
from(projectToConf.configurations.getByName("bundleApi"))
113121
}
114122

115123
val aggregateTestResults: String? by project
@@ -139,6 +147,8 @@ subprojects {
139147
// Bridge that routes log4j calls to log4j2
140148
val log4j2Bridge = "org.apache.logging.log4j:log4j-1.2-api:$log4j2VersionNr"
141149

150+
projectToConf.extra["commons-lang3"] = "org.apache.commons:commons-lang3:3.8.1"
151+
142152
projectToConf.extra["junitVersion"] = junitVersion
143153
projectToConf.extra["log4j2ApiVersion"] = log4j2Api
144154
projectToConf.extra["log4j2CoreVersion"] = log4j2Core

buildSrc/src/main/java/saros/gradle/eclipse/SarosEclipseExtension.java

+20
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class SarosEclipseExtension {
3030
private boolean addDependencies = false;
3131
private boolean addPdeNature = false;
3232
private boolean createBundleJar = false;
33+
private List<String> configs = new ArrayList<>();
3334

3435
public File getManifest() {
3536
return manifest;
@@ -106,4 +107,23 @@ public boolean isCreateBundleJar() {
106107
public void setCreateBundleJar(boolean createBundleJar) {
107108
this.createBundleJar = createBundleJar;
108109
}
110+
111+
public void setConfigs(List<String> configs) {
112+
this.configs = configs;
113+
}
114+
115+
public List<String> getConfigs() {
116+
return configs;
117+
}
118+
119+
/**
120+
* Get the list of (gradle) configurations or a given default if the list of configurations is
121+
* empty.
122+
*
123+
* @param defaultConfigs The list of (gradle) configurations to be returned when an empty
124+
* configurations-list is given.
125+
*/
126+
public List<String> getConfigs(List<String> defaultConfigs) {
127+
return configs.isEmpty() ? defaultConfigs : configs;
128+
}
109129
}

buildSrc/src/main/java/saros/gradle/eclipse/SarosEclipsePlugin.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package saros.gradle.eclipse;
22

3+
import java.util.Arrays;
4+
import java.util.List;
35
import org.gradle.api.GradleException;
46
import org.gradle.api.Plugin;
57
import org.gradle.api.Project;
@@ -16,6 +18,7 @@
1618
public class SarosEclipsePlugin implements Plugin<Project> {
1719
private static final String EXTENSION_NAME = "sarosEclipse";
1820
private static final String PLUGIN_VERSION_CHANGE_TASK_NAME = "changeEclipsePluginVersion";
21+
private static final List<String> DEFAULT_CONFIG_NAMES = Arrays.asList("releaseDep");
1922

2023
/**
2124
* Method which is called when the plugin is integrated in a gradle build (e.g. with {@code apply
@@ -70,7 +73,8 @@ private void configureEclipseAfterEvaluate(Project p, SarosEclipseExtension e) {
7073

7174
if (e.isCreateBundleJar()) {
7275
methodRequiresManifest("create bundle jar", e);
73-
new JarConfigurator(p).createBundleJar(e.getManifest());
76+
List<String> jarConfigs = e.getConfigs(DEFAULT_CONFIG_NAMES);
77+
new JarConfigurator(p, jarConfigs).createBundleJar(e.getManifest());
7478
}
7579

7680
if (e.isAddDependencies()) {

buildSrc/src/main/java/saros/gradle/eclipse/configurator/JarConfigurator.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package saros.gradle.eclipse.configurator;
22

33
import java.io.File;
4+
import java.util.List;
45
import org.gradle.api.GradleException;
56
import org.gradle.api.Project;
67
import org.gradle.api.file.CopySpec;
@@ -14,13 +15,14 @@ public class JarConfigurator {
1415
private static final String JAVA_PLUGIN_ID = "java";
1516
private static final String JAR_TASK_NAME = "jar";
1617

17-
private static final String RELEASE_CONFIG_NAME = "releaseDep";
1818
private static final String JAR_LIB_DESTINATION = "lib";
1919

2020
private Project project;
21+
private final List<String> configs;
2122

22-
public JarConfigurator(Project project) {
23+
public JarConfigurator(Project project, List<String> configs) {
2324
this.project = project;
25+
this.configs = configs;
2426
project.getPluginManager().apply(JAVA_PLUGIN_ID);
2527
}
2628

@@ -33,8 +35,10 @@ public void createBundleJar(File manifestFile) {
3335
jarTask.manifest((Manifest mf) -> mf.from(manifestFile));
3436
SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
3537
jarTask.from(sourceSets.getByName(JAVA_MAIN_SOURCE_SET_NAME).getOutput());
36-
jarTask.into(
37-
JAR_LIB_DESTINATION,
38-
(CopySpec cs) -> cs.from(project.getConfigurations().getByName(RELEASE_CONFIG_NAME)));
38+
for (String jarConfig : this.configs) {
39+
jarTask.into(
40+
JAR_LIB_DESTINATION,
41+
(CopySpec cs) -> cs.from(project.getConfigurations().getByName(jarConfig)));
42+
}
3943
}
4044
}

core/build.gradle.kts

+31-19
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,38 @@
11
plugins {
22
id("saros.gradle.eclipse.plugin")
3+
`java-library`
34
}
45

56
val versionQualifier = ext.get("versionQualifier") as String
7+
val commonsLang = ext.get("commons-lang3") as String
68

79
val log4j2ApiVersion = ext.get("log4j2ApiVersion") as String
810
val log4j2CoreVersion = ext.get("log4j2CoreVersion") as String
911
val log4j2BridgeVersion = ext.get("log4j2BridgeVersion") as String
1012

1113
configurations {
14+
val bundle by getting {}
15+
val bundleApi by getting {}
16+
val api by getting {
17+
extendsFrom(bundleApi)
18+
}
19+
val implementation by getting {
20+
extendsFrom(bundle)
21+
}
1222
// Defined in root build.gradle
1323
val testConfig by getting {}
14-
val releaseDep by getting {}
1524

16-
// Default configuration
17-
val compile by getting {
18-
extendsFrom(releaseDep)
25+
// populate releaseDep while it is still used by other projects
26+
val releaseDep by getting {
27+
extendsFrom(bundle, bundleApi)
1928
}
29+
30+
// Default configuration
2031
val testCompile by getting {
2132
extendsFrom(testConfig)
2233
}
2334
val plain by creating {
24-
extendsFrom(compile)
35+
extendsFrom(implementation, api)
2536
}
2637
}
2738

@@ -30,29 +41,30 @@ sarosEclipse {
3041
isCreateBundleJar = true
3142
isAddPdeNature = true
3243
pluginVersionQualifier = versionQualifier
44+
configs = listOf("bundle", "bundleApi")
3345
}
3446

3547
dependencies {
36-
releaseDep("commons-codec:commons-codec:1.3")
37-
releaseDep("commons-io:commons-io:2.0.1")
38-
releaseDep("org.apache.commons:commons-lang3:3.8.1")
48+
bundle("commons-codec:commons-codec:1.3")
49+
bundleApi("commons-io:commons-io:2.0.1")
50+
bundleApi(commonsLang)
3951

40-
releaseDep("javax.jmdns:jmdns:3.4.1")
41-
releaseDep("xpp3:xpp3:1.1.4c")
42-
releaseDep("com.thoughtworks.xstream:xstream:1.4.10")
43-
releaseDep("org.gnu.inet:libidn:1.15")
52+
bundleApi("javax.jmdns:jmdns:3.4.1")
53+
bundleApi("xpp3:xpp3:1.1.4c")
54+
bundleApi("com.thoughtworks.xstream:xstream:1.4.10")
55+
bundle("org.gnu.inet:libidn:1.15")
4456

45-
releaseDep(log4j2ApiVersion)
46-
releaseDep(log4j2CoreVersion)
47-
releaseDep(log4j2BridgeVersion)
57+
bundleApi(log4j2ApiVersion)
58+
bundleApi(log4j2CoreVersion)
59+
bundleApi(log4j2BridgeVersion)
4860

4961
// TODO: use real release. This version is a customized SNAPSHOT
50-
releaseDep(files("libs/weupnp.jar"))
62+
bundleApi(files("libs/weupnp.jar"))
5163
// Workaround until we updated to a newer smack version
52-
releaseDep(files("libs/smack-3.4.1.jar"))
53-
releaseDep(files("libs/smackx-3.4.1.jar"))
64+
bundleApi(files("libs/smack-3.4.1.jar"))
65+
bundleApi(files("libs/smackx-3.4.1.jar"))
5466
// Workaround until we can publish and use (without a user token) the repackaged jar in GitHub Packages
55-
releaseDep(rootProject.files("libs/picocontainer-2.11.2-patched_relocated.jar"))
67+
bundleApi(rootProject.files("libs/picocontainer-2.11.2-patched_relocated.jar"))
5668
}
5769

5870
sourceSets {

0 commit comments

Comments
 (0)