Maven-code-formatter插件忽略了我的java文件

时间:2014-06-28 02:07:46

标签: eclipse maven maven-plugin

我在Maven中有以下配置,但它只是忽略了我的源文件。调试日志表明,由于符合性级别,Eclipse Code Formatter冷却为null。我检查过,所有级别都是1.8。完整记录下面......

输出:

[INFO] --- maven-java-formatter-plugin:0.4:format (format) @ AIM ---
[INFO] Using 'UTF-8' encoding to format source files.
[INFO] Number of files to be formatted: 67
[INFO] Successfully formatted: 0 file(s)
[INFO] Fail to format        : 0 file(s)
[INFO] Skipped               : 67 file(s)
[INFO] Approximate time taken: 0s
[INFO] 


    <plugin>
  <groupId>com.googlecode.maven-java-formatter-plugin</groupId>
  <artifactId>maven-java-formatter-plugin</artifactId>
  <version>0.4</version>

   <executions>
          <execution>
          <id>format</id> 
          <phase>process-resources</phase> 
             <goals>
              <goal>format</goal>
            </goals>
          </execution>
        </executions>
  <configuration>
   <complianceLevel>${maven.compiler.source}</complianceLevel>
    <sourceLevel>${maven.compiler.source}</sourceLevel>
<!--     <includes> -->
<!--         <include>**/*.java</include> -->
<!--     </includes> -->
     <configFile>${project.basedir}/src/main/resources/eclipse-formatter.xml</configFile>

   <compilerSource default-value="${maven.compiler.source}">${maven.compiler.source}</compilerSource>  
  <compilerTargetPlatform default-value="${maven.compiler.source}">${maven.compiler.source}</compilerTargetPlatform> 
  <compilerTarget default-value="${maven.compiler.target}">${maven.compiler.target}</compilerTarget>
   <overrideConfigCompilerVersion>false</overrideConfigCompilerVersion>  
<!--      <compilerSource>${maven.compiler.target}</compilerSource> -->
<!--     <compilerCompliance>${maven.compiler.target}</compilerCompliance> -->
<!--     <compilerTargetPlatform>${maven.compiler.target}</compilerTargetPlatform> -->
    <lineEnding>AUTO</lineEnding>
    <encoding>${project.build.sourceEncoding}</encoding>
<!--     <excludes> -->
<!--       <exclude>com/relativitas/maven/plugins/formatter/special/</exclude> -->
<!--       <exclude>**/*Test.java</exclude> -->
<!--     </excludes> -->
  </configuration>
</plugin>





Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T11:37:52-06:00)
Maven home: /usr/local/Cellar/maven/3.2.1/libexec
Java version: 1.8.0_05, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.3", arch: "x86_64", family: "mac"
[INFO] Error stacktraces are turned on.
[DEBUG] Reading global settings from /usr/local/Cellar/maven/3.2.1/libexec/conf/settings.xml
[DEBUG] Reading user settings from /Users/user/.m2/settings.xml
[DEBUG] Using local repository at /Users/user/.m2/repository
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10.0 for /Users/user/.m2/repository
[INFO] Scanning for projects...
[DEBUG] Extension realms for project com.domain:AIM:war:0.0.1-SNAPSHOT: (none)
[DEBUG] Looking up lifecyle mappings for packaging war from ClassRealm[plexus.core, parent: null]
[DEBUG] Resolving plugin prefix java-formatter from [org.apache.maven.plugins, org.codehaus.mojo]
[DEBUG] Resolved plugin prefix java-formatter to com.googlecode.maven-java-formatter-plugin:maven-java-formatter-plugin from POM com.domain:AIM:war:0.0.1-SNAPSHOT
[DEBUG] === REACTOR BUILD PLAN ================================================
[DEBUG] Project: com.domain:AIM:war:0.0.1-SNAPSHOT
[DEBUG] Tasks:   [java-formatter:format]
[DEBUG] Style:   Regular
[DEBUG] =======================================================================
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building AIM Maven Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[DEBUG] Resolving plugin prefix java-formatter from [org.apache.maven.plugins, org.codehaus.mojo]
[DEBUG] Resolved plugin prefix java-formatter to com.googlecode.maven-java-formatter-plugin:maven-java-formatter-plugin from POM com.domain:AIM:war:0.0.1-SNAPSHOT
[DEBUG] Lifecycle default -> [validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy]
[DEBUG] Lifecycle clean -> [pre-clean, clean, post-clean]
[DEBUG] Lifecycle site -> [pre-site, site, post-site, site-deploy]
[DEBUG] === PROJECT BUILD PLAN ================================================
[DEBUG] Project:       com.domain:AIM:0.0.1-SNAPSHOT
[DEBUG] Dependencies (collect): []
[DEBUG] Dependencies (resolve): []
[DEBUG] Repositories (dependencies): [central (http://repo1.maven.org/maven2, releases), java.net2 (http://download.java.net/maven/2, releases+snapshots), com.springsource.repository.bundles.release (http://repository.springsource.com/maven/bundles/release, releases+snapshots), com.springsource.repository.bundles.external (http://repository.springsource.com/maven/bundles/external, releases+snapshots), spring-milestones (http://repo.spring.io/milestone, releases+snapshots)]
[DEBUG] Repositories (plugins)     : [central (http://repo.maven.apache.org/maven2, releases)]
[DEBUG] -----------------------------------------------------------------------
[DEBUG] Goal:          com.googlecode.maven-java-formatter-plugin:maven-java-formatter-plugin:0.4:format (default-cli)
[DEBUG] Style:         Regular
[DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <basedir>${basedir}</basedir>
  <compilerCompliance default-value="1.5">${maven.compiler.source}</compilerCompliance>
  <compilerSource default-value="1.8">1.8</compilerSource>
  <compilerTargetPlatform default-value="1.8">1.8</compilerTargetPlatform>
  <configFile>file:///Users/user/Projects/domain/java/AIM3.0/src/main/resources/eclipse-formatter.xml</configFile>
  <encoding default-value="${project.build.sourceEncoding}">UTF-8</encoding>
  <lineEnding default-value="AUTO">AUTO</lineEnding>
  <overrideConfigCompilerVersion default-value="false">false</overrideConfigCompilerVersion>
  <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
  <targetDirectory>${project.build.directory}</targetDirectory>
  <testSourceDirectory>${project.build.testSourceDirectory}</testSourceDirectory>
</configuration>
[DEBUG] =======================================================================
[INFO] 
[INFO] --- maven-java-formatter-plugin:0.4:format (default-cli) @ AIM ---
[DEBUG] Created new class realm maven.api
[DEBUG] Importing foreign packages into class realm maven.api
[DEBUG]   Imported: org.apache.maven.cli < plexus.core
[DEBUG]   Imported: org.eclipse.aether.internal.impl < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.lifecycle < plexus.core
[DEBUG]   Imported: org.apache.maven.lifecycle < plexus.core
[DEBUG]   Imported: org.apache.maven.repository < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.personality < plexus.core
[DEBUG]   Imported: org.apache.maven.usability < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.configuration < plexus.core
[DEBUG]   Imported: javax.enterprise.inject.* < plexus.core
[DEBUG]   Imported: org.apache.maven.* < plexus.core
[DEBUG]   Imported: org.apache.maven.project < plexus.core
[DEBUG]   Imported: org.apache.maven.exception < plexus.core
[DEBUG]   Imported: org.eclipse.aether.spi < plexus.core
[DEBUG]   Imported: org.apache.maven.plugin < plexus.core
[DEBUG]   Imported: org.eclipse.aether.collection < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.* < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.logging < plexus.core
[DEBUG]   Imported: org.apache.maven.profiles < plexus.core
[DEBUG]   Imported: org.eclipse.aether.transfer < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.util.xml.pull.XmlPullParserException < plexus.core
[DEBUG]   Imported: org.apache.maven.execution.scope < plexus.core
[DEBUG]   Imported: org.apache.maven.wagon.* < plexus.core
[DEBUG]   Imported: org.apache.maven.rtinfo < plexus.core
[DEBUG]   Imported: org.eclipse.aether.impl < plexus.core
[DEBUG]   Imported: org.apache.maven.monitor < plexus.core
[DEBUG]   Imported: org.eclipse.aether.graph < plexus.core
[DEBUG]   Imported: org.eclipse.aether.metadata < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.context < plexus.core
[DEBUG]   Imported: org.apache.maven.wagon.observers < plexus.core
[DEBUG]   Imported: org.apache.maven.wagon.resource < plexus.core
[DEBUG]   Imported: javax.inject.* < plexus.core
[DEBUG]   Imported: org.apache.maven.model < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.util.xml.Xpp3Dom < plexus.core
[DEBUG]   Imported: org.eclipse.aether.deployment < plexus.core
[DEBUG]   Imported: org.apache.maven.artifact < plexus.core
[DEBUG]   Imported: org.apache.maven.toolchain < plexus.core
[DEBUG]   Imported: org.eclipse.aether.resolution < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.util.xml.pull.XmlSerializer < plexus.core
[DEBUG]   Imported: org.apache.maven.settings < 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.authentication < plexus.core
[DEBUG]   Imported: org.apache.maven.reporting < plexus.core
[DEBUG]   Imported: org.eclipse.aether.repository < plexus.core
[DEBUG]   Imported: org.slf4j.* < plexus.core
[DEBUG]   Imported: org.apache.maven.wagon.repository < plexus.core
[DEBUG]   Imported: org.apache.maven.configuration < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.classworlds < plexus.core
[DEBUG]   Imported: org.codehaus.classworlds < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.util.xml.pull.XmlPullParser < plexus.core
[DEBUG]   Imported: org.apache.maven.classrealm < plexus.core
[DEBUG]   Imported: org.eclipse.aether.* < plexus.core
[DEBUG]   Imported: org.eclipse.aether.artifact < plexus.core
[DEBUG]   Imported: org.apache.maven.execution < plexus.core
[DEBUG]   Imported: org.apache.maven.wagon.proxy < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.container < plexus.core
[DEBUG]   Imported: org.eclipse.aether.version < plexus.core
[DEBUG]   Imported: org.eclipse.aether.installation < plexus.core
[DEBUG]   Imported: org.codehaus.plexus.component < plexus.core
[DEBUG] Populating class realm maven.api
[DEBUG] Dependency collection stats: {ConflictMarker.analyzeTime=1, ConflictMarker.markTime=1, ConflictMarker.nodeCount=21, ConflictIdSorter.graphTime=0, ConflictIdSorter.topsortTime=1, ConflictIdSorter.conflictIdCount=17, ConflictIdSorter.conflictIdCycleCount=0, ConflictResolver.totalTime=6, ConflictResolver.conflictItemCount=21, DefaultDependencyCollector.collectTime=81, DefaultDependencyCollector.transformTime=11}
[DEBUG] com.googlecode.maven-java-formatter-plugin:maven-java-formatter-plugin:jar:0.4:
[DEBUG]    org.apache.maven:maven-plugin-api:jar:2.0:compile
[DEBUG]    org.eclipse.tycho:org.eclipse.jdt.core:jar:3.8.1.v20120125-1544:compile
[DEBUG]    org.jibx.config.3rdparty.org.eclipse:org.eclipse.text:jar:3.5.100.v20110505-0800:compile
[DEBUG]    org.jibx.config.3rdparty.org.eclipse:org.eclipse.core.runtime:jar:3.7.0.v20110110:compile
[DEBUG]    org.jibx.config.3rdparty.org.eclipse:org.eclipse.core.resources:jar:3.7.100.v20110510-0712:compile
[DEBUG]    org.jibx.config.3rdparty.org.eclipse:org.eclipse.equinox.common:jar:3.6.0.v20110523:compile
[DEBUG]    commons-digester:commons-digester:jar:2.0:compile
[DEBUG]       commons-beanutils:commons-beanutils:jar:1.8.0:compile
[DEBUG]       commons-logging:commons-logging:jar:1.1.1:compile
[DEBUG]    commons-codec:commons-codec:jar:1.4:compile
[DEBUG]    org.codehaus.plexus:plexus-io:jar:1.0.1:compile
[DEBUG]    org.codehaus.plexus:plexus-resources:jar:1.0-alpha-7:compile
[DEBUG]       org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1:compile
[DEBUG]          junit:junit:jar:3.8.1:compile
[DEBUG]          classworlds:classworlds:jar:1.1-alpha-2:compile
[DEBUG]    org.codehaus.plexus:plexus-utils:jar:2.0.5:compile
[DEBUG] Created new class realm plugin>com.googlecode.maven-java-formatter-plugin:maven-java-formatter-plugin:0.4
[DEBUG] Importing foreign packages into class realm plugin>com.googlecode.maven-java-formatter-plugin:maven-java-formatter-plugin:0.4
[DEBUG]   Imported:  < maven.api
[DEBUG] Populating class realm plugin>com.googlecode.maven-java-formatter-plugin:maven-java-formatter-plugin:0.4
[DEBUG]   Included: com.googlecode.maven-java-formatter-plugin:maven-java-formatter-plugin:jar:0.4
[DEBUG]   Included: org.eclipse.tycho:org.eclipse.jdt.core:jar:3.8.1.v20120125-1544
[DEBUG]   Included: org.jibx.config.3rdparty.org.eclipse:org.eclipse.text:jar:3.5.100.v20110505-0800
[DEBUG]   Included: org.jibx.config.3rdparty.org.eclipse:org.eclipse.core.runtime:jar:3.7.0.v20110110
[DEBUG]   Included: org.jibx.config.3rdparty.org.eclipse:org.eclipse.core.resources:jar:3.7.100.v20110510-0712
[DEBUG]   Included: org.jibx.config.3rdparty.org.eclipse:org.eclipse.equinox.common:jar:3.6.0.v20110523
[DEBUG]   Included: commons-digester:commons-digester:jar:2.0
[DEBUG]   Included: commons-beanutils:commons-beanutils:jar:1.8.0
[DEBUG]   Included: commons-logging:commons-logging:jar:1.1.1
[DEBUG]   Included: commons-codec:commons-codec:jar:1.4
[DEBUG]   Included: org.codehaus.plexus:plexus-io:jar:1.0.1
[DEBUG]   Included: org.codehaus.plexus:plexus-resources:jar:1.0-alpha-7
[DEBUG]   Included: junit:junit:jar:3.8.1
[DEBUG]   Included: org.codehaus.plexus:plexus-utils:jar:2.0.5
[DEBUG]   Excluded: org.apache.maven:maven-plugin-api:jar:2.0
[DEBUG]   Excluded: org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1
[DEBUG]   Excluded: classworlds:classworlds:jar:1.1-alpha-2
[DEBUG] Configuring mojo com.googlecode.maven-java-formatter-plugin:maven-java-formatter-plugin:0.4:format from plugin realm ClassRealm[plugin>com.googlecode.maven-java-formatter-plugin:maven-java-formatter-plugin:0.4, parent: sun.misc.Launcher$AppClassLoader@2503dbd3]
[DEBUG] Configuring mojo 'com.googlecode.maven-java-formatter-plugin:maven-java-formatter-plugin:0.4:format' with basic configurator -->
[DEBUG]   (f) basedir = /Users/user/Projects/domain/java/AIM3.0
[DEBUG]   (f) compilerCompliance = 1.8
[DEBUG]   (f) compilerSource = 1.8
[DEBUG]   (f) compilerTargetPlatform = 1.8
[DEBUG]   (f) configFile = file:///Users/user/Projects/domain/java/AIM3.0/src/main/resources/eclipse-formatter.xml
[DEBUG]   (f) encoding = UTF-8
[DEBUG]   (f) lineEnding = AUTO
[DEBUG]   (f) overrideConfigCompilerVersion = false
[DEBUG]   (f) sourceDirectory = /Users/user/Projects/domain/java/AIM3.0/src/main/java
[DEBUG]   (f) targetDirectory = /Users/user/Projects/domain/java/AIM3.0/target
[DEBUG]   (f) testSourceDirectory = /Users/user/Projects/domain/java/AIM3.0/src/test/java
[DEBUG] -- end configuration --
[INFO] Using 'UTF-8' encoding to format source files.
[INFO] Number of files to be formatted: 67
[DEBUG] The resource 'file:///Users/user/Projects/domain/java/AIM3.0/src/main/resources/eclipse-formatter.xml' was not found with resourceLoader org.codehaus.plexus.resource.loader.FileResourceLoader.
[DEBUG] The resource 'file:///Users/user/Projects/domain/java/AIM3.0/src/main/resources/eclipse-formatter.xml' was found as file:/Users/user/Projects/domain/java/AIM3.0/src/main/resources/eclipse-formatter.xml.
[DEBUG] Processing file: /Users/user/Projects/domain/java/AIM3.0/src/main/java/com/domain/biz/dao/IGenericDAO.java
[DEBUG] Code cannot be formatted. Possible cause is unmatched source/target/compliance version.


[DEBUG] Code cannot be formatted. Possible cause is unmatched source/target/compliance version.
[INFO] Successfully formatted: 0 file(s)
[INFO] Fail to format        : 0 file(s)
[INFO] Skipped               : 67 file(s)
[INFO] Approximate time taken: 0s
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.539 s
[INFO] Finished at: 2014-06-28T05:34:53-06:00
[INFO] Final Memory: 9M/307M
[INFO] ------------------------------------------------------------------------

2 个答案:

答案 0 :(得分:0)

您需要升级插件使用的Eclipse版本,并确保配置文件中的版本与项目中的版本一致。这个配置适用于Java8。

<plugin>
  <groupId>com.googlecode.maven-java-formatter-plugin</groupId>
  <artifactId>maven-java-formatter-plugin</artifactId>
  <version>0.4</version>
  <configuration>
    <configFile>${project.basedir}/eclipse-formatter-config.xml</configFile>
    <overrideConfigCompilerVersion>true</overrideConfigCompilerVersion>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>org.eclipse.text</groupId>
      <artifactId>org.eclipse.text</artifactId>
      <version>3.5.101</version>
    </dependency>
    <dependency>
      <groupId>org.eclipse.tycho</groupId>
      <artifactId>org.eclipse.jdt.core</artifactId>
      <version>3.10.0.v20140604-1726</version>
    </dependency>
  </dependencies>
  <executions>
    <execution>
      <phase>format</phase>
      <goals>
        <goal>format</goal>
      </goals>
    </execution>
  </executions>
</plugin>

请注意,我安装了格式生命周期扩展,因此您需要重新编写<extensions/>块或将该生命周期添加到项目中:

<extensions>
  <extension>
    <groupId>com.xiantrimble.maven</groupId>
    <artifactId>maven-format-lifecycle</artifactId>
    <version>1.0.0</version>
  </extension>
</extensions>

使用以下命令运行formatter:

mvn format

答案 1 :(得分:0)

我在跳过Java源文件方面遇到了类似的问题。我发现问题出现在最新的Eclipse版本中,我用它来生成我的XML配置文件。

maven代码格式化程序(版本0.4)仅适用于Eclipse格式化程序3.8:https://code.google.com/p/maven-java-formatter-plugin/wiki/Features

在我下载较旧的Eclipse版本并再次生成我的XML配置文件后,一切正常,文件没有被跳过。

如果您遇到同样的问题,请先尝试使用一个绝对有效的配置文件来运行您的格式化程序,例如:https://code.google.com/p/google-styleguide/source/browse/trunk/eclipse-java-google-style.xml ...确保问题不在于您的XML配置文件。

我不确定这是上述问题的答案,因为没有声明配置文件是如何生成的...但我希望这个答案能节省一些时间......