{"id":632,"date":"2019-03-04T14:50:07","date_gmt":"2019-03-04T06:50:07","guid":{"rendered":"https:\/\/www.zhuyanbin.com\/?p=632"},"modified":"2019-03-04T15:42:15","modified_gmt":"2019-03-04T07:42:15","slug":"gradle-the-java-library-plugin-configurations","status":"publish","type":"post","link":"https:\/\/www.yanbin888.com\/?p=632","title":{"rendered":"Gradle: The Java Library plugin configurations"},"content":{"rendered":"\n<p>The following graph describes the main configurations setup when the Java Library plugin is in use.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"261\" src=\"https:\/\/www.zhuyanbin.com\/wp-content\/uploads\/2019\/03\/01.png\" alt=\"\" class=\"wp-image-633\" srcset=\"https:\/\/www.yanbin888.com\/wp-content\/uploads\/2019\/03\/01.png 1000w, https:\/\/www.yanbin888.com\/wp-content\/uploads\/2019\/03\/01-300x78.png 300w, https:\/\/www.yanbin888.com\/wp-content\/uploads\/2019\/03\/01-768x200.png 768w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>The configurations in&nbsp;<em>green<\/em>&nbsp;are the ones a user should use to declare dependencies<\/li><li>The configurations in&nbsp;<em>pink<\/em>&nbsp;are the ones used when a component compiles, or runs against the library<\/li><li>The configurations in&nbsp;<em>blue<\/em>&nbsp;are internal to the component, for its own use<\/li><li>The configurations in&nbsp;<em>white<\/em>&nbsp;are configurations inherited from the Java plugin<\/li><\/ul>\n\n\n\n<p>And the next graph describes the test configurations setup:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"456\" src=\"https:\/\/www.zhuyanbin.com\/wp-content\/uploads\/2019\/03\/02.png\" alt=\"\" class=\"wp-image-634\" srcset=\"https:\/\/www.yanbin888.com\/wp-content\/uploads\/2019\/03\/02.png 1000w, https:\/\/www.yanbin888.com\/wp-content\/uploads\/2019\/03\/02-300x137.png 300w, https:\/\/www.yanbin888.com\/wp-content\/uploads\/2019\/03\/02-768x350.png 768w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/figure>\n\n\n\n<p>The&nbsp;<em>compile<\/em>,&nbsp;<em>testCompile<\/em>,&nbsp;<em>runtime<\/em>&nbsp;and&nbsp;<em>testRuntime<\/em>&nbsp;configurations inherited from the Java plugin are still available but are deprecated. You should avoid using them, as they are only kept for backwards compatibility.<\/p>\n\n\n\n<p>The role of each configuration is described in the following tables:<\/p>\n\n\n\n<p><em>Table 1. Java Library plugin &#8211; configurations used to declare dependencies<\/em><\/p>\n\n\n\n<table class=\"wp-block-table has-fixed-layout is-style-regular\"><thead><tr><th>Configuration name<\/th><th>Role<\/th><th>Consumable?<\/th><th>Resolvable?<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>api<\/code><\/td><td>Declaring API dependencies<\/td><td>no<\/td><td>no<\/td><td>This is where you should declare dependencies which are transitively exported to consumers, for compile.<\/td><\/tr><tr><td><code>implementation<\/code><\/td><td>Declaring implementation dependencies<\/td><td>no<\/td><td>no<\/td><td>This is where you should declare dependencies which are purely internal and not meant to be exposed to consumers.<\/td><\/tr><tr><td><code>compileOnly<\/code><\/td><td>Declaring compile only dependencies<\/td><td>yes<\/td><td>yes<\/td><td>This is where you should declare dependencies which are only required at compile time, but should not leak into the runtime. This typically includes dependencies which are shaded when found at runtime.<\/td><\/tr><tr><td><code>runtimeOnly<\/code><\/td><td>Declaring runtime dependencies<\/td><td>no<\/td><td>no<\/td><td>This is where you should declare dependencies which are only required at runtime, and not at compile time.<\/td><\/tr><tr><td><code>testImplementation<\/code><\/td><td>Test dependencies<\/td><td>no<\/td><td>no<\/td><td>This is where you should declare dependencies which are used to compile tests.<\/td><\/tr><tr><td><code>testCompileOnly<\/code><\/td><td>Declaring test compile only dependencies<\/td><td>yes<\/td><td>yes<\/td><td>This is where you should declare dependencies which are only required at test compile time, but should not leak into the runtime. This typically includes dependencies which are shaded when found at runtime.<\/td><\/tr><tr><td><code>testRuntimeOnly<\/code><\/td><td>Declaring test runtime dependencies<\/td><td>no<\/td><td>no<\/td><td>This is where you should declare dependencies which are only required at test runtime, and not at test compile time.<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p><em>Table 2. Java Library plugin \u2014 configurations used by consumers<\/em><\/p>\n\n\n\n<table class=\"wp-block-table has-fixed-layout is-style-regular\"><thead><tr><th>Configuration name<\/th><th>Role<\/th><th>Consumable?<\/th><th>Resolvable?<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>apiElements<\/code><\/td><td>For compiling against this library<\/td><td>yes<\/td><td>no<\/td><td>This configuration is meant to be used by consumers, to retrieve all the elements necessary to compile against this library. Unlike the&nbsp;<code>default<\/code>&nbsp;configuration, this doesn\u2019t leak implementation or runtime dependencies.<\/td><\/tr><tr><td><code>runtimeElements<\/code><\/td><td>For executing this library<\/td><td>yes<\/td><td>no<\/td><td>This configuration is meant to be used by consumers, to retrieve all the elements necessary to run against this library.<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p><em>Table 3. Java Library plugin &#8211; configurations used by the library itself<\/em><\/p>\n\n\n\n<table class=\"wp-block-table has-fixed-layout is-style-regular\"><thead><tr><th>Configuration name<\/th><th>Role<\/th><th>Consumable?<\/th><th>Resolvable?<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>compileClasspath<\/td><td>For compiling this library<\/td><td>no<\/td><td>yes<\/td><td>This configuration contains the compile classpath of this library, and is therefore used when invoking the java compiler to compile it.<\/td><\/tr><tr><td>runtimeClasspath<\/td><td>For executing this library<\/td><td>no<\/td><td>yes<\/td><td>This configuration contains the runtime classpath of this library<\/td><\/tr><tr><td>testCompileClasspath<\/td><td>For compiling the tests of this library<\/td><td>no<\/td><td>yes<\/td><td>This configuration contains the test compile classpath of this library.<\/td><\/tr><tr><td>testRuntimeClasspath<\/td><td>For executing tests of this library<\/td><td>no<\/td><td>yes<\/td><td>This configuration contains the test runtime classpath of this library<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p>Link: <a href=\"https:\/\/docs.gradle.org\/current\/userguide\/java_library_plugin.html\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"\uff08\u5728\u65b0\u7a97\u53e3\u6253\u5f00\uff09\">https:\/\/docs.gradle.org\/current\/userguide\/java_library_plugin.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The following graph describes the main configurations s <span class=\"ellipsis\">&hellip;<\/span> <span class=\"more-link-wrap\"><a href=\"https:\/\/www.yanbin888.com\/?p=632\" class=\"more-link\"><span>Read More &rarr;<\/span><\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55,57],"tags":[56,58],"class_list":["post-632","post","type-post","status-publish","format-standard","hentry","category-gradle","category-java","tag-gradle","tag-java"],"_links":{"self":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts\/632","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=632"}],"version-history":[{"count":14,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts\/632\/revisions"}],"predecessor-version":[{"id":653,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts\/632\/revisions\/653"}],"wp:attachment":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=632"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=632"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=632"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}