<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[Heck's  Blog]]></title> 
<link>https://www.heckjj.com/index.php</link> 
<description><![CDATA[一瞬间的决定，往往可以改变很多，事实上，让自己成功的往往不是知识，是精神！ 如果你总是为自己找借口，那只好让成功推迟。执行力，今天！]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[Heck's  Blog]]></copyright>
<item>
<link>https://www.heckjj.com/post//</link>
<title><![CDATA[Maven Dependency Scope]]></title> 
<author>Heck &lt;@hecks.tk&gt;</author>
<category><![CDATA[编程杂谈]]></category>
<pubDate>Fri, 18 Aug 2017 07:01:20 +0000</pubDate> 
<guid>https://www.heckjj.com/post//</guid> 
<description>
<![CDATA[ 
	<p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.2000007629395px"><strong>Dependency scope 是用来限制Dependency的作用范围的, 影响maven项目在各个生命周期时导入的package的状态。</strong></p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">自从2.0.9后，新增了1种，现在有了6种<strong style="color: black; background-color: #99ff99">scope</strong>:</p><ul style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial"><li style="margin: 0px; padding: 0px"><strong>compile</strong><br />默认的<strong style="color: black; background-color: #99ff99">scope</strong>，表示 dependency 都可以在生命周期中使用。而且，这些dependencies 会传递到依赖的项目中。</li><li style="margin: 0px; padding: 0px"><strong>provided</strong><br />跟compile相似，但是表明了dependency 由JDK或者容器提供，例如Servlet AP和一些Java EE APIs。这个<strong style="color: black; background-color: #99ff99">scope</strong> 只能作用在编译和测试时，同时没有传递性。</li><li style="margin: 0px; padding: 0px"><span style="color: #800080"><strong>使用这个时，不会将包打入本项目中，只是依赖过来。&nbsp;&nbsp; </strong></span></li><li style="margin: 0px; padding: 0px"><span style="color: #800080"><strong>使用默认或其他时，会将依赖的项目打成jar包，放入本项目的Lib里</strong></span></li><li style="margin: 0px; padding: 0px">when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.</li><li style="margin: 0px; padding: 0px"><div class="dp-highlighter" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; font-size: 12px; width: 679px; overflow: auto; margin-left: 9px; padding: 1px; word-break: break-all; word-wrap: break-word; background-color: transparent"><div class="bar"><div class="tools" style="padding: 3px; margin: 0px; color: black; font-weight: bold">Xml代码 </div></div><ol class="dp-xml" style="font-size: 1em; line-height: 1.4em; margin: 0px 0px 1px; padding: 2px 0px; border: 1px solid #d1d7dc; color: #2b91af"><li style="margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; font-size: 1em; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa"><span style="color: black"><span style="padding: 0px; margin: 0px; width: auto; border: 0px; color: #008200" class="comments">&lt;!-- Servlet --&gt;</span>&nbsp;&nbsp;</span></li><li style="margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; font-size: 1em; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa"><span style="color: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight: bold; color: #006699" class="tag">&lt;</span><span style="font-weight: bold; color: #006699" class="tag-name">dependency</span><span style="font-weight: bold; color: #006699" class="tag">&gt;</span>&nbsp;&nbsp;</span></li><li style="margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; font-size: 1em; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa"><span style="color: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight: bold; color: #006699" class="tag">&lt;</span><span style="font-weight: bold; color: #006699" class="tag-name">groupId</span><span style="font-weight: bold; color: #006699" class="tag">&gt;</span>javax.servlet<span style="font-weight: bold; color: #006699" class="tag">&lt;/</span><span style="font-weight: bold; color: #006699" class="tag-name">groupId</span><span style="font-weight: bold; color: #006699" class="tag">&gt;</span>&nbsp;&nbsp;</span></li><li style="margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; font-size: 1em; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa"><span style="color: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight: bold; color: #006699" class="tag">&lt;</span><span style="font-weight: bold; color: #006699" class="tag-name">artifactId</span><span style="font-weight: bold; color: #006699" class="tag">&gt;</span>servlet-api<span style="font-weight: bold; color: #006699" class="tag">&lt;/</span><span style="font-weight: bold; color: #006699" class="tag-name">artifactId</span><span style="font-weight: bold; color: #006699" class="tag">&gt;</span>&nbsp;&nbsp;</span></li><li style="margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; font-size: 1em; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa"><span style="color: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight: bold; color: #006699" class="tag">&lt;</span><span style="font-weight: bold; color: #006699" class="tag-name">version</span><span style="font-weight: bold; color: #006699" class="tag">&gt;</span>2.5<span style="font-weight: bold; color: #006699" class="tag">&lt;/</span><span style="font-weight: bold; color: #006699" class="tag-name">version</span><span style="font-weight: bold; color: #006699" class="tag">&gt;</span>&nbsp;&nbsp;</span></li><li style="margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; font-size: 1em; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa"><span style="color: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight: bold; color: #006699" class="tag">&lt;</span><span style="font-weight: bold; color: #006699" class="tag-name">scope</span><span style="font-weight: bold; color: #006699" class="tag">&gt;</span>provided<span style="font-weight: bold; color: #006699" class="tag">&lt;/</span><span style="font-weight: bold; color: #006699" class="tag-name">scope</span><span style="font-weight: bold; color: #006699" class="tag">&gt;</span>&nbsp;&nbsp;</span></li><li style="margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; font-size: 1em; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa"><span style="color: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight: bold; color: #006699" class="tag">&lt;/</span><span style="font-weight: bold; color: #006699" class="tag-name">dependency</span><span style="font-weight: bold; color: #006699" class="tag">&gt;</span>&nbsp;&nbsp;</span></li><li style="margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; font-size: 1em; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa"><span style="color: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight: bold; color: #006699" class="tag">&lt;</span><span style="font-weight: bold; color: #006699" class="tag-name">dependency</span><span style="font-weight: bold; color: #006699" class="tag">&gt;</span>&nbsp;&nbsp;</span></li><li style="margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; font-size: 1em; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa"><span style="color: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight: bold; color: #006699" class="tag">&lt;</span><span style="font-weight: bold; color: #006699" class="tag-name">groupId</span><span style="font-weight: bold; color: #006699" class="tag">&gt;</span>javax.servlet.jsp<span style="font-weight: bold; color: #006699" class="tag">&lt;/</span><span style="font-weight: bold; color: #006699" class="tag-name">groupId</span><span style="font-weight: bold; color: #006699" class="tag">&gt;</span>&nbsp;&nbsp;</span></li><li style="margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; font-size: 1em; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa"><span style="color: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight: bold; color: #006699" class="tag">&lt;</span><span style="font-weight: bold; color: #006699" class="tag-name">artifactId</span><span style="font-weight: bold; color: #006699" class="tag">&gt;</span>jsp-api<span style="font-weight: bold; color: #006699" class="tag">&lt;/</span><span style="font-weight: bold; color: #006699" class="tag-name">artifactId</span><span style="font-weight: bold; color: #006699" class="tag">&gt;</span>&nbsp;&nbsp;</span></li><li style="margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; font-size: 1em; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa"><span style="color: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight: bold; color: #006699" class="tag">&lt;</span><span style="font-weight: bold; color: #006699" class="tag-name">version</span><span style="font-weight: bold; color: #006699" class="tag">&gt;</span>2.1<span style="font-weight: bold; color: #006699" class="tag">&lt;/</span><span style="font-weight: bold; color: #006699" class="tag-name">version</span><span style="font-weight: bold; color: #006699" class="tag">&gt;</span>&nbsp;&nbsp;</span></li><li style="margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; font-size: 1em; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa"><span style="color: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight: bold; color: #006699" class="tag">&lt;</span><span style="font-weight: bold; color: #006699" class="tag-name">scope</span><span style="font-weight: bold; color: #006699" class="tag">&gt;</span>provided<span style="font-weight: bold; color: #006699" class="tag">&lt;/</span><span style="font-weight: bold; color: #006699" class="tag-name">scope</span><span style="font-weight: bold; color: #006699" class="tag">&gt;</span>&nbsp;&nbsp;</span></li><li style="margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px; font-size: 1em; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; line-height: 18px; background-color: #fafafa"><span style="color: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight: bold; color: #006699" class="tag">&lt;/</span><span style="font-weight: bold; color: #006699" class="tag-name">dependency</span><span style="font-weight: bold; color: #006699" class="tag">&gt;</span>&nbsp;&nbsp;</span></li></ol></div> </li></ul><ul style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial"><li style="margin: 0px; padding: 0px"><strong>runtime</strong><br />表示dependency不作用在编译时，但会作用在运行和测试时</li><li style="margin: 0px; padding: 0px"><strong>test</strong><br />表示dependency作用在测试时，不作用在运行时。</li><li style="margin: 0px; padding: 0px"><strong>system</strong><br />跟provided 相似，但是<strong>在系统中要以外部JAR包的形式提供</strong>，maven不会在repository查找它。 例如：</li></ul><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&lt;project&gt;<br />...<br />&lt;dependencies&gt;<br />　　&lt;dependency&gt;<br />　　　&lt;groupId&gt;javax.sql&lt;/groupId&gt;<br />　　　&lt;artifactId&gt;jdbc-stdext&lt;/artifactId&gt;<br />　　　&lt;version&gt;2.0&lt;/version&gt;<br />　　　&lt;<strong style="color: black; background-color: #99ff99">scope</strong>&gt;system&lt;/<strong style="color: black; background-color: #99ff99">scope</strong>&gt;<br />　　　&lt;systemPath&gt;$&#123;java.home&#125;/lib/rt.jar&lt;/systemPath&gt;<br />　　&lt;/dependency&gt;<br />&lt;/dependencies&gt;<br />...<br />&lt;/project&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial"> </p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial"> </p><ul style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial"><li style="margin: 0px; padding: 0px"><strong>import </strong><em>(Maven 2.0.9 </em><em>之后新增)</em><br /><strong>它只使用在&lt;dependencyManagement&gt;中</strong>，表示从其它的pom中导入<strong style="color: black; background-color: #ffff66">dependency</strong>的配置，例如：&nbsp;&nbsp;&nbsp;&nbsp;This <strong style="color: black; background-color: #99ff99">scope</strong> is only used on a dependency of type pom in the &lt;dependencyManagement&gt; section. It indicates that the specified POM should be replaced with the dependencies in that POM's &lt;dependencyManagement&gt; section. Since they are replaced, dependencies with a <strong style="color: black; background-color: #99ff99">scope</strong> of <strong style="color: black; background-color: #ff9999">import</strong> do not actually participate in limiting the transitivity of a dependency.</li></ul><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&lt;project&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&lt;groupId&gt;maven&lt;/groupId&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&lt;artifactId&gt;B&lt;/artifactId&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&lt;packaging&gt;pom&lt;/packaging&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&lt;name&gt;B&lt;/name&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&lt;version&gt;1.0&lt;/version&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial"> </p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&lt;dependencyManagement&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&nbsp;&nbsp;&nbsp;&nbsp;&lt;dependencies&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;<strong style="color: black; background-color: #ffff66">dependency</strong>&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;groupId&gt;maven&lt;/groupId&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;artifactId&gt;A&lt;/artifactId&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;version&gt;1.0&lt;/version&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;type&gt;pom&lt;/type&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;<strong style="color: black; background-color: #99ff99">scope</strong>&gt;<strong style="color: black; background-color: #ff9999">import</strong>&lt;/<strong style="color: black; background-color: #99ff99">scope</strong>&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/<strong style="color: black; background-color: #ffff66">dependency</strong>&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;<strong style="color: black; background-color: #ffff66">dependency</strong>&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;groupId&gt;test&lt;/groupId&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;artifactId&gt;d&lt;/artifactId&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;version&gt;1.0&lt;/version&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/<strong style="color: black; background-color: #ffff66">dependency</strong>&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&nbsp;&nbsp;&nbsp;&nbsp;&lt;/dependencies&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&lt;/dependencyManagement&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">&lt;/project&gt;</p><p style="margin: 0px; padding: 0px; font-size: 14px; line-height: 25.2000007629395px; color: #454545; font-family: tahoma, helvetica, arial">B项目导入A项目中的包配置</p>
]]>
</description>
</item><item>
<link>https://www.heckjj.com/post//#blogcomment</link>
<title><![CDATA[[评论] Maven Dependency Scope]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://www.heckjj.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>