635
阿里云
技术社区[云栖]
OBTAINING SPRING 3 ARTIFACTS WITH MAVEN
原文:https://blog.springsource.com/2009/12/02/obtaining-spring-3-artifacts-with-maven/
A recent commentor here ragged, "It's only half of the world that's using Maven", when pointing
out it is not obvious how to obtain Spring 3 artifacts with Maven. In this entry, I'll show you how to do this and what the options are. This information will also be integrated into the reference documentation of the upcoming Spring 3 final release.
MAVEN REPOSITORIES WHERE SPRING ARTIFACTS ARE PUBLISHED
In general, Spring publishes its artifacts to two different places:
-
Maven Central, which is the default repository Maven queries, and does not require any special configuration
to use
-
The Enterprise Bundle Repository (EBR), which is run by SpringSource and also hosts all the
libraries that integrate with Spring
So the first thing you need to decide when obtaining Spring with Maven is which place you'll get it from. In general, if you care about OSGi, use the EBR, since it houses OSGi
compatible artifacts for all of Spring's dependencies, such as Hibernate and Freemarker. If OSGi does not matter to you, either place works, though there are some pros and cons between them. In general, pick one place or the other for your project;
do not mix them. This is particularly important since EBR artifacts use a different naming convention than Maven Central artifacts.
Below is a table that compares Maven Central to the EBR in several areas:
Feature |
Maven Central |
Enterprise Bundle Repository (EBR) |
OSGi Compatible |
No |
Yes |
Number of Artifacts |
Tens of thousands; all kinds |
Hundreds; those that Spring integrates/supports |
Consistent Naming Conventions for all Artifacts? |
No |
Yes |
Artifact Naming Convention |
Group id
Varies; newer artifacts use domain name e.g. "org.sl4j"; older artifacts use artifact id e.g. "log4j"
Artifact id
Varies; typically the JAR file name minus extension e.g. "log4j" Version
Varies; most use numbers and dots e.g. "3.0.0"
|
Group id
<Domain name> e.g. "org.springframework" Artifact id
<Bundle-SymbolicName>, derived from main package e.g. "org.springframework.beans". If the JAR had to be patched to ensure OSGi compliance, "com.springsource." is prepended e.g. "com.springsource.org.apache.log4j" Version
OSGi version number format of <major>.<minor>.<micro>[.qualifier] e.g. "3.0.0.RC3" |
Publishing |
Automatic (rSync via remote repositories) |
Manual (JIRA processed by SpringSource) |
Quality Assurance |
None I am aware of; Accuracy is responsibility of publishing organization |
Extensive (for both MANIFEST.mf and .pom); QA is performed by Spring Team |
Hosting |
@ Contegix funded by Sonatype with several mirrors |
S3 funded by SpringSource |
Search Utilities |
Various |
www.springsource.com/repository
|
Integrated with SpringSource Tools (STS, Roo, etc) |
Yes, with STS and Roo |
Yes, with STS |
Now that you know the options, I'll discuss how to obtain Spring artifacts from both places.
OBTAINING SPRING RELEASES FROM MAVEN CENTRAL
You do not have to add a repository to your .pom to obtain final releases of Spring projects from Maven Central. Simply add the dependencies your project requires.
A .pom <dependency> snippet for each Spring Framework 3 artifact as it will be indexed in Maven Central is listed below.
<!-- Shared version number properties -->
|
<org.springframework.version>3.0.5.RELEASE</org.springframework.version>
|
Core
utilities used by other modules.
|
Define
this if you use Spring Utility APIs (org.springframework.core.*/org.springframework.util.*)
|
<groupId>org.springframework</groupId>
|
<artifactId>spring-core</artifactId>
|
<version>${org.springframework.version}</version>
|
Expression
Language (depends on spring-core)
|
Define
this if you use Spring Expression APIs (org.springframework.expression.*)
|
<groupId>org.springframework</groupId>
|
<artifactId>spring-expression</artifactId>
|
<version>${org.springframework.version}</version>
|
Bean
Factory and JavaBeans utilities (depends on spring-core)
|
Define
this if you use Spring Bean APIs (org.springframework.beans.*)
|
<groupId>org.springframework</groupId>
|
<artifactId>spring-beans</artifactId>
|
<version>${org.springframework.version}</version>
|
Aspect
Oriented Programming (AOP) Framework (depends on spring-core, spring-beans)
|
Define
this if you use Spring AOP APIs (org.springframework.aop.*)
|
<groupId>org.springframework</groupId>
|
<artifactId>spring-aop</artifactId>
|
<version>${org.springframework.version}</version>
|
Application
Context (depends on spring-core, spring-expression, spring-aop, spring-beans)
|
This
is the central artifact for Spring's Dependency Injection Container and is generally always defined
|
<groupId>org.springframework</groupId>
|
<artifactId>spring-context</artifactId>
|
<version>${org.springframework.version}</version>
|
Various
Application Context utilities, including EhCache, JavaMail, Quartz, and Freemarker integration
|
Define
this if you need any of these integrations
|
<groupId>org.springframework</groupId>
|
<artifactId>spring-context-support</artifactId>
|
<version>${org.springframework.version}</version>
|
Transaction
Management Abstraction (depends on spring-core, spring-beans, spring-aop, spring-context)
|
Define
this if you use Spring Transactions or DAO Exception Hierarchy
|
(org.springframework.transaction.*/org.springframework.dao.*)
|
<groupId>org.springframework</groupId>
|
<artifactId>spring-tx</artifactId>
|
<version>${org.springframework.version}</version>
|
JDBC
Data Access Library (depends on spring-core, spring-beans, spring-context, spring-tx)
|
Define
this if you use Spring's JdbcTemplate API (org.springframework.jdbc.*)
|
<groupId>org.springframework</groupId>
|
<artifactId>spring-jdbc</artifactId>
|
<version>${org.springframework.version}</version>
|
Object-to-Relation-Mapping
(ORM) integration with Hibernate, JPA, and iBatis.
|
(depends
on spring-core, spring-beans, spring-context, spring-tx)
|
Define
this if you need ORM (org.springframework.orm.*)
|
<groupId>org.springframework</groupId>
|
<artifactId>spring-orm</artifactId>
|
<version>${org.springframework.version}</version>
|
Object-to-XML
Mapping (OXM) abstraction and integration with JAXB, JiBX, Castor, XStream, and XML Beans.
|
(depends
on spring-core, spring-beans, spring-context)
|
Define
this if you need OXM (org.springframework.oxm.*)
|
<groupId>org.springframework</groupId>
|
<artifactId>spring-oxm</artifactId>
|
<version>${org.springframework.version}</version>
|
Web
application development utilities applicable to both Servlet and Portlet Environments
|
(depends
on spring-core, spring-beans, spring-context)
|
Define
this if you use Spring MVC, or wish to use Struts, JSF, or another web framework with Spring (org.springframework.web.*)
|
<groupId>org.springframework</groupId>
|
<artifactId>spring-web</artifactId>
|
<version>${org.springframework.version}</version>
|
Spring
MVC for Servlet Environments (depends on spring-core, spring-beans, spring-context, spring-web)
|
Define
this if you use Spring MVC with a Servlet Container such as Apache Tomcat (org.springframework.web.servlet.*)
|
<groupId>org.springframework</groupId>
|
<artifactId>spring-webmvc</artifactId>
|
<version>${org.springframework.version}</version>
|
Spring
MVC for Portlet Environments (depends on spring-core, spring-beans, spring-context, spring-web)
|
Define
this if you use Spring MVC with a Portlet Container (org.springframework.web.portlet.*)
|
<groupId>org.springframework</groupId>
|
<artifactId>spring-webmvc-portlet</artifactId>
|
<version>${org.springframework.version}</version>
|
Support
for testing Spring applications with tools such as JUnit and TestNG
|
This
artifact is generally always defined with a 'test' scope for the integration testing framework and unit testing stubs
|
<groupId>org.springframework</groupId>
|
<artifactId>spring-test</artifactId>
|
<version>${org.springframework.version}</version>
|
OBTAINING SPRING RELEASES FROM THE ENTERPRISE BUNDLE REPOSITORY (EBR)
To obtain final releases of Spring projects from the EBR, add the following repositories to your .pom:
<id>com.springsource.repository.bundles.release</id>
|
<name>EBR
Spring Release Repository</name>
|
<url>https://
repository.springsource.com/maven/bundles/release</url>
|
<id>com.springsource.repository.bundles.external</id>
|
<name>EBR
External Release Repository</name>
|
<url>https://
repository.springsource.com/maven/bundles/external</url>
|
Then simply add the dependencies your project requires, keeping in mind the EBR artifact naming conventions.
A .pom <dependency> snippet for each Spring Framework 3 artifact as it will be indexed in the EBR is listed below:
<!-- Shared version number properties -->
|
<org.springframework.version>3.0.0.RELEASE</org.springframework.version>
|
Core
utilities used by other modules.
|
Define
this if you use Spring Utility APIs (org.springframework.core.*/org.springframework.util.*)
|
<groupId>org.springframework</groupId>
|
<artifactId>org.springframework.core</artifactId>
|
<version>${org.springframework.version}</version>
|
Expression
Language (depends on core)
|
Define
this if you use Spring Expression APIs (org.springframework.expression.*)
|
<groupId>org.springframework</groupId>
|
<artifactId>org.springframework.expression</artifactId>
|
<version>${org.springframework.version}</version>
|
Bean
Factory and JavaBeans utilities (depends on core)
|
Define
this if you use Spring Bean APIs (org.springframework.beans.*)
|
<groupId>org.springframework</groupId>
|
<artifactId>org.springframework.beans</artifactId>
|
<version>${org.springframework.version}</version>
|
Aspect
Oriented Programming (AOP) Framework (depends on core, beans)
|
Define
this if you use Spring AOP APIs (org.springframework.aop.*)
|
<groupId>org.springframework</groupId>
|
<artifactId>org.springframework.aop</artifactId>
|
<version>${org.springframework.version}</version>
|
Application
Context (depends on core, expression, aop, beans)
|
This
is the central artifact for Spring's Dependency Injection Container and is generally always defined
|
<groupId>org.springframework</groupId>
|
<artifactId>org.springframework.context</artifactId>
|
<version>${org.springframework.version}</version>
|
Various
Application Context utilities, including EhCache, JavaMail, Quartz, and Freemarker integration
|
Define
this if you need any of these integrations
|
<groupId>org.springframework</groupId>
|
<artifactId>org.springframework.context.support</artifactId>
|
<version>${org.springframework.version}</version>
|
Transaction
Management Abstraction (depends on core, beans, aop, context)
|
Define
this if you use Spring Transactions or DAO Exception Hierarchy
|
(org.springframework.transaction.*/org.springframework.dao.*)
|
<groupId>org.springframework</groupId>
|
<artifactId>org.springframework.transaction</artifactId>
|
<version>${org.springframework.version}</version>
|
JDBC
Data Access Library (depends on core, beans, context, transaction)
|
Define
this if you use Spring's JdbcTemplate API (org.springframework.jdbc.*)
|
<groupId>org.springframework</groupId>
|
<artifactId>org.springframework.jdbc</artifactId>
|
<version>${org.springframework.version}</version>
|
Object-to-Relation-Mapping
(ORM) integration with Hibernate, JPA, and iBatis.
|
(depends
on core, beans, context, transaction)
|
Define
this if you need ORM (org.springframework.orm.*)
|
<groupId>org.springframework</groupId>
|
<artifactId>org.springframework.orm</artifactId>
|
<version>${org.springframework.version}</version>
|
Object-to-XML
Mapping (OXM) abstraction and integration with JAXB, JiBX, Castor, XStream, and XML Beans.
|
(depends
on core, beans, context)
|
Define
this if you need OXM (org.springframework.oxm.*)
|
<groupId>org.springframework</groupId>
|
<artifactId>org.springframework.oxm</artifactId>
|
<version>${org.springframework.version}</version>
|
Web
app development utilities common across Servlet/Portlet environments (depends on core, beans, context)
|
Define
this if you use Spring MVC, or wish to use Struts, JSF, or another web framework with Spring (org.springframework.web.*)
|
<groupId>org.springframework</groupId>
|
<artifactId>org.springframework.web</artifactId>
|
<version>${org.springframework.version}</version>
|
Spring
MVC for Servlet Environments (depends on core, beans, context, web)
|
Define
this if you use Spring MVC with a Servlet Container such as Apache Tomcat (org.springframework.web.servlet.*)
|
<groupId>org.springframework</groupId>
|
<artifactId>org.springframework.web.servlet</artifactId>
|
<version>${org.springframework.version}</version>
|
Spring
MVC for Portlet Environments (depends on core, beans, context, web)
|
Define
this if you use Spring MVC with a Portlet Container (org.springframework.web.portlet.*)
|
<groupId>org.springframework</groupId>
|
<artifactId>org.springframework.web.portlet</artifactId>
|
<version>${org.springframework.version}</version>
|
Support
for testing Spring applications with tools such as JUnit and TestNG
|
This
artifact is generally always defined with a 'test' scope for the integration testing framework and unit testing stubs
|
<groupId>org.springframework</groupId>
|
<artifactId>org.springframework.test</artifactId>
|
<version>${org.springframework.version}</version>
|
OBTAINING SPRING MILESTONE RELEASES
Milestones and Release Candidates may not be published directly to Maven Central, and in general are published separately from final releases. SpringSource hosts two repositories for obtaining Spring milestones. The first one should be used in conjunction with
Maven Central, and the second one in conjunction with the EBR.
Obtaining Milestones from the Maven Central Compatible Repository
To obtain Spring milestones from the Maven Central compatible repository, add the following repository to your .pom:
<id>org.springframework.maven.milestone</id>
|
<name>Maven
Central Compatible Spring Milestone Repository</name>
|
<url>https://
maven.springframework.org/milestone</url>
|
The milestone version number format is <major>.<minor>.<micro>.M#; for example, 3.0.0.M4. The release candidate version number format is <major>.<minor>.<micro>.RC#; for example, 3.0.0.RC3.
For example, adding the following dependency would retrieve version 3.0.0.RC3 of the spring-context artifact:
<groupId>org.springframework</groupId>
|
<artifactId>spring-context</artifactId>
|
<version>3.0.0.RC3</version>
|
Obtaining Milestones from the Enterprise Bundle Repository (EBR)
To obtain Spring milestones from the EBR, add the following repository to your .pom:
<id>com.springsource.repository.bundles.milestone</id>
|
<name>EBR
Spring Milestone Repository</name>
|
<url>https://
repository.springsource.com/maven/bundles/milestone</url>
|
Be sure to keep in mind the distinct EBR artifact naming convention. For example, adding the following dependency would retrieve version 3.0.0.RC3 of the org.springframework.context artifact:
<groupId>org.springframework</groupId>
|
<artifactId>org.springframework.context</artifactId&g 最后更新:2017-04-03 16:48:50
|