@@ -79,8 +79,9 @@ class BuildPlugin implements Plugin<Project> {
7979 }
8080 project. pluginManager. apply(' java' )
8181 project. pluginManager. apply(' carrotsearch.randomized-testing' )
82- // these plugins add lots of info to our jars
82+ configureConfigurations(project)
8383 configureJars(project) // jar config must be added before info broker
84+ // these plugins add lots of info to our jars
8485 project. pluginManager. apply(' nebula.info-broker' )
8586 project. pluginManager. apply(' nebula.info-basic' )
8687 project. pluginManager. apply(' nebula.info-java' )
@@ -91,8 +92,8 @@ class BuildPlugin implements Plugin<Project> {
9192
9293 globalBuildInfo(project)
9394 configureRepositories(project)
94- configureConfigurations(project)
9595 project. ext. versions = VersionProperties . versions
96+ configureSourceSets(project)
9697 configureCompile(project)
9798 configureJavadoc(project)
9899 configureSourcesJar(project)
@@ -421,8 +422,10 @@ class BuildPlugin implements Plugin<Project> {
421422 project. configurations. compile. dependencies. all(disableTransitiveDeps)
422423 project. configurations. testCompile. dependencies. all(disableTransitiveDeps)
423424 project. configurations. compileOnly. dependencies. all(disableTransitiveDeps)
425+
424426 project. plugins. withType(ShadowPlugin ). whenPluginAdded {
425- project. configurations. shadow. dependencies. all(disableTransitiveDeps)
427+ Configuration bundle = project. configurations. create(' bundle' )
428+ bundle. dependencies. all(disableTransitiveDeps)
426429 }
427430 }
428431
@@ -556,37 +559,27 @@ class BuildPlugin implements Plugin<Project> {
556559 publications {
557560 nebula(MavenPublication ) {
558561 artifacts = [ project. tasks. shadowJar ]
559- artifactId = project. archivesBaseName
560- /*
561- * Configure the pom to include the "shadow" as compile dependencies
562- * because that is how we're using them but remove all other dependencies
563- * because they've been shaded into the jar.
564- */
565- pom. withXml { XmlProvider xml ->
566- Node root = xml. asNode()
567- root. remove(root. dependencies)
568- Node dependenciesNode = root. appendNode(' dependencies' )
569- project. configurations. shadow. allDependencies. each {
570- if (false == it instanceof SelfResolvingDependency ) {
571- Node dependencyNode = dependenciesNode. appendNode(' dependency' )
572- dependencyNode. appendNode(' groupId' , it. group)
573- dependencyNode. appendNode(' artifactId' , it. name)
574- dependencyNode. appendNode(' version' , it. version)
575- dependencyNode. appendNode(' scope' , ' compile' )
576- }
577- }
578- // Be tidy and remove the element if it is empty
579- if (dependenciesNode. children. empty) {
580- root. remove(dependenciesNode)
581- }
582- }
583562 }
584563 }
585564 }
586565 }
587566 }
588567 }
589568
569+ /**
570+ * Add dependencies that we are going to bundle to the compile classpath.
571+ */
572+ static void configureSourceSets (Project project ) {
573+ project. plugins. withType(ShadowPlugin ). whenPluginAdded {
574+ [' main' , ' test' ]. each {name ->
575+ SourceSet sourceSet = project. sourceSets. findByName(name)
576+ if (sourceSet != null ) {
577+ sourceSet. compileClasspath + = project. configurations. bundle
578+ }
579+ }
580+ }
581+ }
582+
590583 /* * Adds compiler settings to the project */
591584 static void configureCompile (Project project ) {
592585 if (project. compilerJavaVersion < JavaVersion . VERSION_1_10 ) {
@@ -764,9 +757,16 @@ class BuildPlugin implements Plugin<Project> {
764757 * better to be safe
765758 */
766759 mergeServiceFiles()
760+ /*
761+ * Bundle dependencies of the "bundled" configuration.
762+ */
763+ configurations = [project. configurations. bundle]
767764 }
768765 // Make sure we assemble the shadow jar
769766 project. tasks. assemble. dependsOn project. tasks. shadowJar
767+ project. artifacts {
768+ apiElements project. tasks. shadowJar
769+ }
770770 }
771771 }
772772
@@ -873,13 +873,8 @@ class BuildPlugin implements Plugin<Project> {
873873 exclude ' **/*$*.class'
874874
875875 project. plugins. withType(ShadowPlugin ). whenPluginAdded {
876- /*
877- * If we make a shaded jar we test against it.
878- */
876+ // Test against a shadow jar if we made one
879877 classpath - = project. tasks. compileJava. outputs. files
880- classpath - = project. configurations. compile
881- classpath - = project. configurations. runtime
882- classpath + = project. configurations. shadow
883878 classpath + = project. tasks. shadowJar. outputs. files
884879 dependsOn project. tasks. shadowJar
885880 }
@@ -905,26 +900,6 @@ class BuildPlugin implements Plugin<Project> {
905900 additionalTest. dependsOn(project. tasks. testClasses)
906901 project. check. dependsOn(additionalTest)
907902 });
908-
909- project. plugins. withType(ShadowPlugin ). whenPluginAdded {
910- /*
911- * We need somewhere to configure dependencies that we don't wish
912- * to shade into the jar. The shadow plugin creates a "shadow"
913- * configuration which is *almost* exactly that. It is never
914- * bundled into the shaded jar but is used for main source
915- * compilation. Unfortunately, by default it is not used for
916- * *test* source compilation and isn't used in tests at all. This
917- * change makes it available for test compilation.
918- *
919- * Note that this isn't going to work properly with qa projects
920- * but they have no business applying the shadow plugin in the
921- * firstplace.
922- */
923- SourceSet testSourceSet = project. sourceSets. findByName(' test' )
924- if (testSourceSet != null ) {
925- testSourceSet. compileClasspath + = project. configurations. shadow
926- }
927- }
928903 }
929904
930905 private static configurePrecommit (Project project ) {
@@ -936,7 +911,7 @@ class BuildPlugin implements Plugin<Project> {
936911 it. group. startsWith(' org.elasticsearch' ) == false
937912 } - project. configurations. compileOnly
938913 project. plugins. withType(ShadowPlugin ). whenPluginAdded {
939- project. dependencyLicenses. dependencies + = project. configurations. shadow . fileCollection {
914+ project. dependencyLicenses. dependencies + = project. configurations. bundle . fileCollection {
940915 it. group. startsWith(' org.elasticsearch' ) == false
941916 }
942917 }
@@ -947,7 +922,7 @@ class BuildPlugin implements Plugin<Project> {
947922 deps. runtimeConfiguration = project. configurations. runtime
948923 project. plugins. withType(ShadowPlugin ). whenPluginAdded {
949924 deps. runtimeConfiguration = project. configurations. create(' infoDeps' )
950- deps. runtimeConfiguration. extendsFrom(project. configurations. runtime, project. configurations. shadow )
925+ deps. runtimeConfiguration. extendsFrom(project. configurations. runtime, project. configurations. bundle )
951926 }
952927 deps. compileOnlyConfiguration = project. configurations. compileOnly
953928 project. afterEvaluate {
0 commit comments