如何在其他maven项目中使用一个maven项目的属性?

问题描述 投票:0回答:1

我有2个独立的项目--第一个项目被添加到第二个项目中作为依赖关系,我不能把它们变成一个独立的项目。模块 因为使用第一个项目的maven项目数量不固定。

第一个项目的几行字

<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>com.test</groupId>
        <artifactId>first</artifactId>
        <version>${artifact.version}</version> 
        <packaging>jar</packaging>
        <properties>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <version.maven-bundle-plugin>3.2.0</version.maven-bundle-plugin>
            <jboss.fuse.bom.version>7.4.0.fuse-740036-redhat-00002</jboss.fuse.bom.version>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <artifact.version>2.0</artifact.version> 
        </properties>

第二项目绒球的几行字--

<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <groupId>com.test</groupId>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>second</artifactId>
    <version>1.0</version>
    <packaging>bundle</packaging>
    <name>second</name>
    <description>second</description>
    <dependencyManagement>
        <dependencies>
            <dependency>
<groupId>com.test</groupId>
            <artifactId>first</artifactId>
            <version>${artifact.version}</version>
        </dependency>
    </dependencies>

当我们使用属性 artifact.version 从第一个项目到第二个项目,我们得到以下的错误,请让我们知道如何处理。对症下药 在其他maven项目中使用一个maven项目的属性。

com.test:first:jar的'dependencies.dependency.version'必须是一个有效的版本,但是是'${artifact.version}'。第93行,第13列

Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T00:30:29+05:30)
Maven home: C:\work\vindhya\test\AllMicroService templates\second-microservice\EMBEDDED
Java version: 1.8.0_241, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jre1.8.0_241
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "test", family: "windows"
[DEBUG] Created new class realm maven.api
[DEBUG] Importing foreign packages into class realm maven.api
[DEBUG]   Imported: javax.annotation.* < plexus.core
[DEBUG]   Imported: javax.annotation.security.* < plexus.core
[DEBUG]   Imported: javax.enterprise.inject.* < plexus.core
[DEBUG]   Imported: javax.enterprise.util.* < plexus.core
[DEBUG]   Imported: javax.inject.* < plexus.core
[DEBUG]   Imported: org.apache.maven.* < plexus.core
[DEBUG]   Imported: org.apache.maven.artifact < plexus.core
[DEBUG]   Imported: org.apache.maven.classrealm < plexus.core
[DEBUG]   Imported: org.apache.maven.cli < plexus.core
[DEBUG]   Imported: org.apache.maven.configuration < plexus.core
[DEBUG]   Imported: org.apache.maven.exception < plexus.core
[DEBUG]   Imported: org.apache.maven.execution < plexus.core
[DEBUG]   Imported: org.apache.maven.execution.scope < plexus.core
[DEBUG]   Imported: org.apache.maven.lifecycle < plexus.core
[DEBUG]   Imported: org.apache.maven.model < plexus.core
[DEBUG]   Imported: org.apache.maven.monitor < plexus.core
[DEBUG]   Imported: org.apache.maven.plugin < plexus.core
[DEBUG]   Imported: org.apache.maven.profiles < plexus.core
[DEBUG]   Imported: org.apache.maven.project < plexus.core
[DEBUG]   Imported: org.apache.maven.reporting < plexus.core
[DEBUG]   Imported: org.apache.maven.repository < plexus.core
[DEBUG]   Imported: org.apache.maven.rtinfo < plexus.core
[DEBUG]   Imported: org.apache.maven.settings < plexus.core
[DEBUG]   Imported: org.apache.maven.toolchain < plexus.core
[DEBUG]   Imported: org.apache.maven.usability < plexus.core
[DEBUG]   Imported: org.apache.maven.wagon.* < plexus.core
[DEBUG]   Imported: org.apache.maven.wagon.authentication < plexus.core
[DEBUG]   Imported: org.apache.maven.wagon.authorization < plexus.core
[DEBUG]   Imported: org.apache.maven.wagon.events < plexus.core
[DEBUG]   Imported: org.apache.maven.wagon.observers < plexus.core
[DEBUG]   Imported: org.apache.maven.wagon.proxy < plexus.core
[DEBUG]   Imported: org.apache.maven.wagon.repository < plexus.core
[DEBUG]   Imported: org.apache.maven.wagon.resource < plexus.core
[DEBUG]   Imported: org.codehaus.classworlds < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.* < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.classworlds < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.component < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.configuration < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.container < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.context < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.lifecycle < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.logging < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.personality < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.util.xml.Xpp3Dom < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.util.xml.pull.XmlPullParser < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.util.xml.pull.XmlPullParserException < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.util.xml.pull.XmlSerializer < plexus.core
[DEBUG]   Imported: org.eclipse.aether.* < plexus.core
[DEBUG]   Imported: org.eclipse.aether.artifact < plexus.core
[DEBUG]   Imported: org.eclipse.aether.collection < plexus.core
[DEBUG]   Imported: org.eclipse.aether.deployment < plexus.core
[DEBUG]   Imported: org.eclipse.aether.graph < plexus.core
[DEBUG]   Imported: org.eclipse.aether.impl < plexus.core
[DEBUG]   Imported: org.eclipse.aether.installation < plexus.core
[DEBUG]   Imported: org.eclipse.aether.internal.impl < plexus.core
[DEBUG]   Imported: org.eclipse.aether.metadata < plexus.core
[DEBUG]   Imported: org.eclipse.aether.repository < plexus.core
[DEBUG]   Imported: org.eclipse.aether.resolution < plexus.core
[DEBUG]   Imported: org.eclipse.aether.spi < plexus.core
[DEBUG]   Imported: org.eclipse.aether.transfer < plexus.core
[DEBUG]   Imported: org.eclipse.aether.version < plexus.core
[DEBUG]   Imported: org.fusesource.jansi.* < plexus.core
[DEBUG]   Imported: org.slf4j.* < plexus.core
[DEBUG]   Imported: org.slf4j.event.* < plexus.core
[DEBUG]   Imported: org.slf4j.helpers.* < plexus.core
[DEBUG]   Imported: org.slf4j.spi.* < plexus.core
[DEBUG] Populating class realm maven.api
[INFO] Error stacktraces are turned on.
[DEBUG] Message scheme: plain
[DEBUG] Reading global settings from settings.xml
[DEBUG] Reading user settings from C:\Users\schintha\.m2\settings.xml
[DEBUG] Reading global toolchains from toolchains.xml
[DEBUG] Reading user toolchains from C:\Users\schintha\.m2\toolchains.xml
[DEBUG] Using local repository at C:\Users\schintha\.m2\repository
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10.0 for C:\Users\schintha\.m2\repository
[INFO] Scanning for projects...
[DEBUG] Dependency collection stats: {ConflictMarker.analyzeTime=3754100, ConflictMarker.markTime=2245000, ConflictMarker.nodeCount=196, ConflictIdSorter.graphTime=2424500, ConflictIdSorter.topsortTime=693700, ConflictIdSorter.conflictIdCount=61, ConflictIdSorter.conflictIdCycleCount=0, ConflictResolver.totalTime=18152100, ConflictResolver.conflictItemCount=131, DefaultDependencyCollector.collectTime=4833984800, DefaultDependencyCollector.transformTime=31287500}
[DEBUG] org.apache.felix:maven-bundle-plugin:jar:3.2.0:
[DEBUG]    org.osgi:org.osgi.core:jar:4.3.1:compile
[DEBUG]    biz.aQute.bnd:biz.aQute.bndlib:jar:3.2.0:compile
[DEBUG]    org.apache.felix:org.apache.felix.bundlerepository:jar:1.6.6:compile
[DEBUG]       org.easymock:easymock:jar:3.4:compile
[DEBUG]          org.objenesis:objenesis:jar:2.2:compile
[DEBUG]    org.apache.felix:org.apache.felix.utils:jar:1.6.0:compile
[DEBUG]       org.osgi:org.osgi.compendium:jar:4.2.0:compile
[DEBUG]    org.apache.maven:maven-core:jar:2.2.0:compile
[DEBUG]       org.apache.maven:maven-settings:jar:2.2.0:compile
[DEBUG]       org.apache.maven:maven-plugin-parameter-documenter:jar:2.2.0:compile
[DEBUG]       org.slf4j:slf4j-jdk14:jar:1.5.6:runtime
[DEBUG]          org.slf4j:slf4j-api:jar:1.5.6:runtime
[DEBUG]       org.slf4j:jcl-over-slf4j:jar:1.5.6:runtime
[DEBUG]       org.apache.maven.reporting:maven-reporting-api:jar:2.2.0:compile
[DEBUG]          org.apache.maven.doxia:doxia-logging-api:jar:1.1:compile
[DEBUG]       org.apache.maven:maven-profile:jar:2.2.0:compile
[DEBUG]       org.apache.maven:maven-model:jar:2.2.0:compile
[DEBUG]       org.apache.maven:maven-artifact:jar:2.2.0:compile
[DEBUG]       org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1:compile
[DEBUG]          junit:junit:jar:4.12:compile
[DEBUG]             org.hamcrest:hamcrest-core:jar:1.3:compile
[DEBUG]       org.apache.maven:maven-repository-metadata:jar:2.2.0:compile
[DEBUG]       org.apache.maven:maven-error-diagnostics:jar:2.2.0:compile
[DEBUG]       org.apache.maven:maven-project:jar:2.2.0:compile
[DEBUG]          org.apache.maven:maven-plugin-registry:jar:2.2.0:compile
[DEBUG]       commons-cli:commons-cli:jar:1.2:compile
[DEBUG]       org.apache.maven:maven-plugin-api:jar:2.2.0:compile
[DEBUG]       org.apache.maven:maven-plugin-descriptor:jar:2.2.0:compile
[DEBUG]       org.codehaus.plexus:plexus-interactivity-api:jar:1.0-alpha-4:compile
[DEBUG]       org.apache.maven:maven-artifact-manager:jar:2.2.0:compile
[DEBUG]          backport-util-concurrent:backport-util-concurrent:jar:3.1:compile
[DEBUG]       org.apache.maven:maven-monitor:jar:2.2.0:compile
[DEBUG]       classworlds:classworlds:jar:1.1:compile
[DEBUG]       org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3:compile
[DEBUG]          org.sonatype.plexus:plexus-cipher:jar:1.4:compile
[DEBUG]    org.apache.maven:maven-archiver:jar:2.5:compile
[DEBUG]       org.codehaus.plexus:plexus-archiver:jar:2.1:compile
[DEBUG]          org.codehaus.plexus:plexus-io:jar:2.0.2:compile
[DEBUG]       org.codehaus.plexus:plexus-interpolation:jar:1.15:compile
[DEBUG]    org.apache.maven.shared:maven-dependency-tree:jar:2.1:compile
[DEBUG]       org.codehaus.plexus:plexus-component-annotations:jar:1.5.5:compile
[DEBUG]       org.eclipse.aether:aether-util:jar:0.9.0.M2:compile
[DEBUG]    org.codehaus.plexus:plexus-utils:jar:3.0.10:compile
[DEBUG]    org.sonatype.plexus:plexus-build-api:jar:0.0.7:compile
[DEBUG]    org.apache.maven.doxia:doxia-sink-api:jar:1.0:compile
[DEBUG]    org.apache.maven.doxia:doxia-site-renderer:jar:1.0:compile
[DEBUG]       org.apache.maven.doxia:doxia-core:jar:1.0:compile
[DEBUG]       org.codehaus.plexus:plexus-i18n:jar:1.0-beta-7:compile
[DEBUG]       org.codehaus.plexus:plexus-velocity:jar:1.1.7:compile
[DEBUG]       org.apache.velocity:velocity:jar:1.5:compile
[DEBUG]          commons-lang:commons-lang:jar:2.1:compile
[DEBUG]          oro:oro:jar:2.0.8:compile
[DEBUG]       org.apache.maven.doxia:doxia-decoration-model:jar:1.0:compile
[DEBUG]       commons-collections:commons-collections:jar:3.2:compile
[DEBUG]       org.apache.maven.doxia:doxia-module-apt:jar:1.0:compile
[DEBUG]       org.apache.maven.doxia:doxia-module-fml:jar:1.0:compile
[DEBUG]       org.apache.maven.doxia:doxia-module-xdoc:jar:1.0:compile
[DEBUG]       org.apache.maven.doxia:doxia-module-xhtml:jar:1.0:compile
[DEBUG]    org.jdom:jdom:jar:1.1:compile
[DEBUG] Created new class realm extension>org.apache.felix:maven-bundle-plugin:3.2.0
[DEBUG] Importing foreign packages into class realm extension>org.apache.felix:maven-bundle-plugin:3.2.0
[DEBUG]   Imported:  < maven.api
[DEBUG] Populating class realm extension>org.apache.felix:maven-bundle-plugin:3.2.0
[DEBUG]   Included: org.apache.felix:maven-bundle-plugin:jar:3.2.0
[DEBUG]   Included: org.osgi:org.osgi.core:jar:4.3.1
[DEBUG]   Included: biz.aQute.bnd:biz.aQute.bndlib:jar:3.2.0
[DEBUG]   Included: org.apache.felix:org.apache.felix.bundlerepository:jar:1.6.6
[DEBUG]   Included: org.easymock:easymock:jar:3.4
[DEBUG]   Included: org.objenesis:objenesis:jar:2.2
[DEBUG]   Included: org.apache.felix:org.apache.felix.utils:jar:1.6.0
[DEBUG]   Included: org.osgi:org.osgi.compendium:jar:4.2.0
[DEBUG]   Included: org.slf4j:slf4j-jdk14:jar:1.5.6
[DEBUG]   Included: org.slf4j:jcl-over-slf4j:jar:1.5.6
[DEBUG]   Included: org.apache.maven.reporting:maven-reporting-api:jar:2.2.0
[DEBUG]   Included: org.apache.maven.doxia:doxia-logging-api:jar:1.1
[DEBUG]   Included: junit:junit:jar:4.12
[DEBUG]   Included: org.hamcrest:hamcrest-core:jar:1.3
[DEBUG]   Included: commons-cli:commons-cli:jar:1.2
[DEBUG]   Included: org.codehaus.plexus:plexus-interactivity-api:jar:1.0-alpha-4
[DEBUG]   Included: backport-util-concurrent:backport-util-concurrent:jar:3.1
[DEBUG]   Included: org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3
[DEBUG]   Included: org.sonatype.plexus:plexus-cipher:jar:1.4
[DEBUG]   Included: org.apache.maven:maven-archiver:jar:2.5
[DEBUG]   Included: org.codehaus.plexus:plexus-archiver:jar:2.1
[DEBUG]   Included: org.codehaus.plexus:plexus-io:jar:2.0.2
[DEBUG]   Included: org.codehaus.plexus:plexus-interpolation:jar:1.15
[DEBUG]   Included: org.apache.maven.shared:maven-dependency-tree:jar:2.1
[DEBUG]   Included: org.codehaus.plexus:plexus-component-annotations:jar:1.5.5
[DEBUG]   Included: org.eclipse.aether:aether-util:jar:0.9.0.M2
[DEBUG]   Included: org.codehaus.plexus:plexus-utils:jar:3.0.10
[DEBUG]   Included: org.sonatype.plexus:plexus-build-api:jar:0.0.7
[DEBUG]   Included: org.apache.maven.doxia:doxia-sink-api:jar:1.0
[DEBUG]   Included: org.apache.maven.doxia:doxia-site-renderer:jar:1.0
[DEBUG]   Included: org.apache.maven.doxia:doxia-core:jar:1.0
[DEBUG]   Included: org.codehaus.plexus:plexus-i18n:jar:1.0-beta-7
[DEBUG]   Included: org.codehaus.plexus:plexus-velocity:jar:1.1.7
[DEBUG]   Included: org.apache.velocity:velocity:jar:1.5
[DEBUG]   Included: commons-lang:commons-lang:jar:2.1
[DEBUG]   Included: oro:oro:jar:2.0.8
[DEBUG]   Included: org.apache.maven.doxia:doxia-decoration-model:jar:1.0
[DEBUG]   Included: commons-collections:commons-collections:jar:3.2
[DEBUG]   Included: org.apache.maven.doxia:doxia-module-apt:jar:1.0
[DEBUG]   Included: org.apache.maven.doxia:doxia-module-fml:jar:1.0
[DEBUG]   Included: org.apache.maven.doxia:doxia-module-xdoc:jar:1.0
[DEBUG]   Included: org.apache.maven.doxia:doxia-module-xhtml:jar:1.0
[DEBUG]   Included: org.jdom:jdom:jar:1.1
[DEBUG] Extension realms for project com.test:second:bundle:1.0: [ClassRealm[extension>org.apache.felix:maven-bundle-plugin:3.2.0, parent: sun.misc.Launcher$AppClassLoader@4e25154f]]
[DEBUG] Created new class realm project>com.test:second:1.0
[DEBUG] Populating class realm project>com.test:second:1.0
[DEBUG] Looking up lifecycle mappings for packaging bundle from ClassRealm[project>com.test:second:1.0, parent: ClassRealm[maven.api, parent: null]]
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] 'dependencies.dependency.version' for com.test:first:jar must be a valid version but is '${artifact.version}'. @ line 93, column 13
 @ 
[ERROR] The build could not read 1 project -> [Help 1]
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[ERROR] 'dependencies.dependency.version' for com.test:first:jar must be a valid version but is '${artifact.version}'. @ line 93, column 13

    at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:395)
    at org.apache.maven.graph.DefaultGraphBuilder.collectProjects(DefaultGraphBuilder.java:414)
    at org.apache.maven.graph.DefaultGraphBuilder.getProjectsForMavenReactor(DefaultGraphBuilder.java:405)
    at org.apache.maven.graph.DefaultGraphBuilder.build(DefaultGraphBuilder.java:82)
    at org.apache.maven.DefaultMaven.buildGraph(DefaultMaven.java:507)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:219)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
[ERROR]   
[ERROR]   The project com.test:second:1.0 (C:\work\vindhya\test\AllMicroService templates\second-microservice\pom.xml) has 1 error
[ERROR]     'dependencies.dependency.version' for com.test:first:jar must be a valid version but is '${artifact.version}'. @ line 93, column 13
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
java maven apache-camel
1个回答
3
投票

不,你不能使用依赖项的属性。

如果你需要共同的属性,你可以在不同项目使用的父POM中定义它们(这不要求它们是模块)。

© www.soinside.com 2019 - 2024. All rights reserved.