Maven pom版本的相对路径

时间:2018-03-07 06:27:12

标签: maven nexus

原谅我的无知,因为我是maven的新手。我有一个远程存储库,我的项目pom用于从中下载依赖项。我的pom.xml的一般结构是这样的:

Query {
_mongooseOptions: {},
mongooseCollection: 
 NativeCollection {
 collection: Collection { s: [Object] },
 opts: 
  { bufferCommands: true,
    capped: false,
    '$wasForceClosed': undefined },
 name: 'soundspots',
 collectionName: 'soundspots',
 conn: 
  NativeConnection {
    base: [Object],
    collections: [Object],
    models: [Object],
    config: [Object],
    replica: false,
    hosts: null,
    host: 'localhost',
    port: 27017,
    user: null,
    pass: null,
    name: 'user_account',
    options: null,
    otherDbs: [],
    states: [Object],
    _readyState: 1,
    _closeCalled: false,
    _hasOpened: true,
    _listening: false,
    _connectionOptions: [Object],
    '$initialConnection': [Object],
    db: [Object],
    client: [Object] },
 queue: [],
 buffer: false,
 emitter: 
  EventEmitter {
    domain: null,
    _events: {},
    _eventsCount: 0,
    _maxListeners: undefined } },
model: 
{ [Function: model]
 hooks: Kareem { _pres: [Object], _posts: [Object] },
 base: 
  Mongoose {
    connections: [Object],
    models: [Object],
    modelSchemas: [Object],
    options: [Object],
    _pluralize: [Function: pluralize],
    plugins: [Object] },
 modelName: 'soundspot',
 model: [Function: model],
 db: 
  NativeConnection {
    base: [Object],
    collections: [Object],
    models: [Object],
    config: [Object],
    replica: false,
    hosts: null,
    host: 'localhost',
    port: 27017,
    user: null,
    pass: null,
    name: 'user_account',
    options: null,
    otherDbs: [],
    states: [Object],
    _readyState: 1,
    _closeCalled: false,
    _hasOpened: true,
    _listening: false,
    _connectionOptions: [Object],
    '$initialConnection': [Object],
    db: [Object],
    client: [Object] },
 discriminators: undefined,
 '$appliedMethods': true,
 authenticate: [Function],
 serializeUser: [Function],
 deserializeUser: [Function],
 register: [Function],
 findByUsername: [Function],
 createStrategy: [Function],
 '$appliedHooks': true,
 schema: 
  Schema {
    obj: [Object],
    paths: [Object],
    aliases: {},
    subpaths: {},
    virtuals: [Object],
    singleNestedPaths: {},
    nested: [Object],
    inherits: {},
    callQueue: [],
    _indexes: [],
    methods: [Object],
    statics: [Object],
    tree: [Object],
    query: {},
    childSchemas: [],
    plugins: [Object],
    s: [Object],
    _userProvidedOptions: undefined,
    options: [Object],
    '$globalPluginsApplied': true },
 collection: 
  NativeCollection {
    collection: [Object],
    opts: [Object],
    name: 'soundspots',
    collectionName: 'soundspots',
    conn: [Object],
    queue: [],
    buffer: false,
    emitter: [Object] },
 Query: { [Function] base: [Object] },
 '$__insertMany': [Function],
 '$init': Promise { [Object], catch: [Function] } },
schema: 
Schema {
 obj: 
  { name: [Function: String],
    key: [Function: String],
    connected: [Object],
    type: [Object],
    location: [Object],
    playlist: [Object] },
 paths: 
  { name: [Object],
    key: [Object],
    'connected.username': [Object],
    type: [Object],
    'location.type': [Object],
    'location.coordinates': [Object],
    'location.longitude': [Object],
    'location.latitude': [Object],
    'playlist.title': [Object],
    'playlist.file': [Object],
    'playlist.votes': [Object],
    _id: [Object],
    username: [Object],
    hash: [Object],
    salt: [Object],
    __v: [Object] },
 aliases: {},
 subpaths: {},
 virtuals: { id: [Object] },
 singleNestedPaths: {},
 nested: { connected: true, location: true, playlist: true },
 inherits: {},
 callQueue: [],
 _indexes: [],
 methods: 
  { setPassword: [Function],
    changePassword: [Function],
    authenticate: [Function] },
 statics: 
  { authenticate: [Function],
    serializeUser: [Function],
    deserializeUser: [Function],
    register: [Function],
    findByUsername: [Function],
    createStrategy: [Function] },
 tree: 
  { name: [Function: String],
    key: [Function: String],
    connected: [Object],
    type: [Object],
    location: [Object],
    playlist: [Object],
    _id: [Object],
    username: [Object],
    hash: [Object],
    salt: [Object],
    __v: [Function: Number],
    id: [Object] },
 query: {},
 childSchemas: [],
 plugins: [ [Object], [Object], [Object], [Object], [Object], [Object] ],
 s: { hooks: [Object] },
 _userProvidedOptions: undefined,
 options: 
  { typeKey: 'type',
    id: true,
    noVirtualId: false,
    _id: true,
    noId: false,
    validateBeforeSave: true,
    read: null,
    shardKey: null,
    autoIndex: null,
    minimize: true,
    discriminatorKey: '__t',
    versionKey: '__v',
    capped: false,
    bufferCommands: true,
    strict: true,
    pluralization: true },
 '$globalPluginsApplied': true },
op: 'find',
options: {},
_conditions: 
{ location: { '$near': [Object], '$maxDistance': 100 },
 _mongooseOption: 'find' },
_fields: undefined,
_update: undefined,
_path: undefined,
_distinct: undefined,
_collection: 
NodeCollection {
 collection: 
  NativeCollection {
    collection: [Object],
    opts: [Object],
    name: 'soundspots',
    collectionName: 'soundspots',
    conn: [Object],
    queue: [],
    buffer: false,
    emitter: [Object] },
 collectionName: 'soundspots' },
_traceFunction: undefined }
Query {
 _mongooseOptions: {},
 mongooseCollection: 
 NativeCollection {
 collection: Collection { s: [Object] },
 opts: 
  { bufferCommands: true,
    capped: false,
    '$wasForceClosed': undefined },
 name: 'soundspots',
 collectionName: 'soundspots',
 conn: 
  NativeConnection {
    base: [Object],
    collections: [Object],
    models: [Object],
    config: [Object],
    replica: false,
    hosts: null,
    host: 'localhost',
    port: 27017,
    user: null,
    pass: null,
    name: 'user_account',
    options: null,
    otherDbs: [],
    states: [Object],
    _readyState: 1,
    _closeCalled: false,
    _hasOpened: true,
    _listening: false,
    _connectionOptions: [Object],
    '$initialConnection': [Object],
    db: [Object],
    client: [Object] },
 queue: [],
 buffer: false,
 emitter: 
  EventEmitter {
    domain: null,
    _events: {},
    _eventsCount: 0,
    _maxListeners: undefined } },
 model: 
   { [Function: model]
 hooks: Kareem { _pres: [Object], _posts: [Object] },
 base: 
  Mongoose {
    connections: [Object],
    models: [Object],
    modelSchemas: [Object],
    options: [Object],
    _pluralize: [Function: pluralize],
    plugins: [Object] },
 modelName: 'soundspot',
 model: [Function: model],
 db: 
  NativeConnection {
    base: [Object],
    collections: [Object],
    models: [Object],
    config: [Object],
    replica: false,
    hosts: null,
    host: 'localhost',
    port: 27017,
    user: null,
    pass: null,
    name: 'user_account',
    options: null,
    otherDbs: [],
    states: [Object],
    _readyState: 1,
    _closeCalled: false,
    _hasOpened: true,
    _listening: false,
    _connectionOptions: [Object],
    '$initialConnection': [Object],
    db: [Object],
    client: [Object] },
 discriminators: undefined,
 '$appliedMethods': true,
 authenticate: [Function],
 serializeUser: [Function],
 deserializeUser: [Function],
 register: [Function],
 findByUsername: [Function],
 createStrategy: [Function],
 '$appliedHooks': true,
 schema: 
  Schema {
    obj: [Object],
    paths: [Object],
    aliases: {},
    subpaths: {},
    virtuals: [Object],
    singleNestedPaths: {},
    nested: [Object],
    inherits: {},
    callQueue: [],
    _indexes: [],
    methods: [Object],
    statics: [Object],
    tree: [Object],
    query: {},
    childSchemas: [],
    plugins: [Object],
    s: [Object],
    _userProvidedOptions: undefined,
    options: [Object],
    '$globalPluginsApplied': true },
 collection: 
  NativeCollection {
    collection: [Object],
    opts: [Object],
    name: 'soundspots',
    collectionName: 'soundspots',
    conn: [Object],
    queue: [],
    buffer: false,
    emitter: [Object] },
 Query: { [Function] base: [Object] },
 '$__insertMany': [Function],
 '$init': Promise { [Object], catch: [Function] } },
 schema: 
  Schema {
  obj: 
  { name: [Function: String],
    key: [Function: String],
    connected: [Object],
    type: [Object],
    location: [Object],
    playlist: [Object] },
   paths: 
   { name: [Object],
    key: [Object],
    'connected.username': [Object],
    type: [Object],
    'location.type': [Object],
    'location.coordinates': [Object],
    'location.longitude': [Object],
    'location.latitude': [Object],
    'playlist.title': [Object],
    'playlist.file': [Object],
    'playlist.votes': [Object],
    _id: [Object],
    username: [Object],
    hash: [Object],
    salt: [Object],
    __v: [Object] },
 aliases: {},
 subpaths: {},
 virtuals: { id: [Object] },
 singleNestedPaths: {},
 nested: { connected: true, location: true, playlist: true },
 inherits: {},
 callQueue: [],
 _indexes: [],
 methods: 
  { setPassword: [Function],
    changePassword: [Function],
    authenticate: [Function] },
 statics: 
  { authenticate: [Function],
    serializeUser: [Function],
    deserializeUser: [Function],
    register: [Function],
    findByUsername: [Function],
    createStrategy: [Function] },
 tree: 
  { name: [Function: String],
    key: [Function: String],
    connected: [Object],
    type: [Object],
    location: [Object],
    playlist: [Object],
    _id: [Object],
    username: [Object],
    hash: [Object],
    salt: [Object],
    __v: [Function: Number],
    id: [Object] },
 query: {},
 childSchemas: [],
 plugins: [ [Object], [Object], [Object], [Object], [Object], [Object] ],
 s: { hooks: [Object] },
 _userProvidedOptions: undefined,
 options: 
  { typeKey: 'type',
    id: true,
    noVirtualId: false,
    _id: true,
    noId: false,
    validateBeforeSave: true,
    read: null,
    shardKey: null,
    autoIndex: null,
    minimize: true,
    discriminatorKey: '__t',
    versionKey: '__v',
    capped: false,
    bufferCommands: true,
    strict: true,
    pluralization: true },
 '$globalPluginsApplied': true },
 op: 'find',
 options: {},
 _conditions: 
 { location: { '$near': [Object], '$maxDistance': 100 },
 _mongooseOption: 'find' },
 _fields: undefined,
 _update: undefined,
 _path: undefined,
 _distinct: undefined,
 _collection: 
 NodeCollection {
 collection: 
  NativeCollection {
    collection: [Object],
    opts: [Object],
    name: 'soundspots',
    collectionName: 'soundspots',
    conn: [Object],
    queue: [],
    buffer: false,
    emitter: [Object] },
 collectionName: 'soundspots' },
 _traceFunction: undefined }

现在我知道如果我必须获得新版本的依赖项<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>MVNProject</groupId> <artifactId>MVNProject</artifactId> <version>0.0.1</version> <packaging>war</packaging> <dependency> <groupId>org.scala-lang.modules</groupId> <artifactId>scala-parser-combinators_2.11</artifactId> <version>1.0.1</version> </dependency> </dependencies> </project> ,我只需要指定新版本。像这样:

scala-parser-combinators

但我想做的是,在不对<dependency> <groupId>org.scala-lang.modules</groupId> <artifactId>scala-parser-combinators_2.11</artifactId> <version>1.0.1</version> </dependency> 进行任何更改的情况下,我想用我的远程存储库中的升级jar替换旧jar(我能够做到)。 / p>

所以我想知道的是,是否有一种方法可以在pom.xml中指定远程存储库中可用于特定工件的任何版本,即类似这样的东西(这只是一个猜):

pom

非常感谢一些指导。

2 个答案:

答案 0 :(得分:0)

如果您使用 maven2 ,则在版本标记中使用最新 RELEASE 值可以自动解决依赖项更新。虽然,此解决方案不适用于 maven3 (不推荐使用)。

如果您使用的是maven3,那么您必须稍微更新settings.xml。快照存储库将获得一个额外的 updatePolicy 标记。这样的事情: -

<repositories>
    <repository>
        <id>you-snapshots</id>
        <url>http://host/nexus/repos/snapshots</url>
        <snapshots>
            <updatePolicy>always</updatePolicy>
        </snapshots>
        <releases>
            <updatePolicy>always</updatePolicy>
        </releases>
    </repository>
</repositories>

此外,Maven还有一个Versions插件,可让您将pom更新为可见存储库中最新的最新快照。它通过检查您的pom并与远程存储库进行比较然后根据需要进行修改来实现此目的。

这是一个有用的工具,但我肯定希望看到与已弃用的LATEST选项相当的东西。我发现这种依赖在持续集成场景中特别有用。

答案 1 :(得分:0)

有些事情需要注意:

  • 您不应该从远程存储库中删除工件的特定发行版本并替换它,例如在远程存储库中使用1.0.1,删除它并再次在1.0.1下上载不同的工件。 Maven在本地存储库中缓存发布版本,因此您永远不会知道您获得了哪个工件。
  • 如果您有更新的版本,请为其提供更新的版本号(如1.0.2)。
  • 现在要走的路不是使用RELEASE或LATEST,而是使用版本插件更新依赖项(如$data = array_map(function($v) use ($keys) { return array_combine($keys, $v); }, $data); )。