The expression ${build.finalName} is deprecated. Please use ${project.build.finalName} instead.

故障背景

今天尝试使用maven Jetty插件启动一个war 项目,无论执行maven的任何命令都会提示这样的警告信息。

[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.xingyun:hello-world-sample:war:1.0-SNAPSHOT
[WARNING] The expression ${build.finalName} is deprecated. Please use ${project.build.finalName} instead.
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 

故障分析

根据提示来看,我们可以看出

The expression ${build.finalName} is deprecated. Please use ${project.build.finalName} instead.

也就是说,${build.finalName} 表达式已经过时了,请使用${project.build.finalName}代替。

但是到底应该改哪里呢???

我刚开始找了半天,都没找到到底应该修改哪里。

直到今天晚上,偶然发现了答案,原来在这个地方。。。

<contextPath>/${build.finalName}contextPath>

之前错误pom.xml 如下所示:


<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.0modelVersion>

    
    <groupId>com.xingyungroupId>
    <artifactId>hello-world-sampleartifactId>
    <version>1.0-SNAPSHOTversion>
    <packaging>warpackaging>

    <properties>
        
        <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
        
        <java.version>12java.version>
        <maven.compiler.source>${java.version}maven.compiler.source>
        <maven.compiler.target>${java.version}maven.compiler.target>
        <maven.compiler.plugin.version>3.8.1maven.compiler.plugin.version>
        
        <skipTests>trueskipTests>
        
        <jetty.maven.plugin.version>9.4.7.v20170914jetty.maven.plugin.version>
    properties>

    <build>
        
        <finalName>hello-world-samplefinalName>
        
        <plugins>
            
            <plugin>
                <groupId>org.eclipse.jettygroupId>
                <artifactId>jetty-maven-pluginartifactId>
                <version>${jetty.maven.plugin.version}version>
                <configuration>
                    <webApp>
                        <contextPath>/${build.finalName}contextPath>
                    webApp>
                    <stopKey>CTRL+CstopKey>
                    <stopPort>8999stopPort>
                    <scanIntervalSeconds>10scanIntervalSeconds>
                    <scanTargets>
                        <scanTarget>src/main/webapp/WEB-INF/web.xmlscanTarget>
                    scanTargets>
                configuration>
            plugin>
            
            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-compiler-pluginartifactId>
                <version>${maven.compiler.plugin.version}version>
                <configuration>
                    <source>${java.version}source>
                    <target>${java.version}target>
                configuration>
            plugin>
        plugins>
    build>
project>

修复解决方案

修复成功的pom.xml配置如下:


<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.0modelVersion>

    
    <groupId>com.xingyungroupId>
    <artifactId>hello-world-sampleartifactId>
    <version>1.0-SNAPSHOTversion>
    <packaging>warpackaging>

    <properties>
        
        <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
        
        <java.version>12java.version>
        <maven.compiler.source>${java.version}maven.compiler.source>
        <maven.compiler.target>${java.version}maven.compiler.target>
        <maven.compiler.plugin.version>3.8.1maven.compiler.plugin.version>
        
        <skipTests>trueskipTests>
        
        <jetty.maven.plugin.version>9.4.7.v20170914jetty.maven.plugin.version>
    properties>

    <build>
        
        <finalName>hello-world-samplefinalName>
        
        <plugins>
            
            <plugin>
                <groupId>org.eclipse.jettygroupId>
                <artifactId>jetty-maven-pluginartifactId>
                <version>${jetty.maven.plugin.version}version>
                <configuration>
                    <webApp>
                        <contextPath>/${project.build.finalName}contextPath>
                    webApp>
                    <stopKey>CTRL+CstopKey>
                    <stopPort>8999stopPort>
                    <scanIntervalSeconds>10scanIntervalSeconds>
                    <scanTargets>
                        <scanTarget>src/main/webapp/WEB-INF/web.xmlscanTarget>
                    scanTargets>
                configuration>
            plugin>
            
            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-compiler-pluginartifactId>
                <version>${maven.compiler.plugin.version}version>
                <configuration>
                    <source>${java.version}source>
                    <target>${java.version}target>
                configuration>
            plugin>
        plugins>
    build>
project>

Tips:
你有没有好奇过如果不设置hello-world-sample会发生什么呢?

  • 如果不设置这个属性的话,那么默认/${project.build.finalName}的值将会是artifactId+version拼接在一起的结果,即:
    http://127.0.0.1:8080/hello-world-sample-1.0-SNAPSHOT
  • 如果按照上面设置后就会变成这样
    http://127.0.0.1:8080/hello-world-sample

你可能感兴趣的:(The,expression,i,build.finalName,id,deprecated,StackOverflow)