openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.88k stars 3.59k forks source link

OH3: Maven build failing (bad format violations in a POM) #8712

Closed lolodomo closed 2 years ago

lolodomo commented 4 years ago

Even using -DskipChecks does not help avoiding this blocking step.

Is there a way to disable this check ?

[INFO] --- spotless-maven-plugin:2.0.3:check (codestyle_check) @ org.openhab.addons.reactor.bundles ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] openHAB Add-ons .................................... SUCCESS [03:12 min]
[INFO] openHAB Add-ons :: BOM ............................. SUCCESS [  0.062 s]
[INFO] openHAB Add-ons :: BOM :: Runtime Index ............ SUCCESS [03:07 min]
[INFO] openHAB Add-ons :: BOM :: Test Index ............... SUCCESS [ 22.930 s]
[INFO] openHAB Add-ons :: BOM :: openHAB Core Index ....... SUCCESS [01:54 min]
[INFO] openHAB Add-ons :: Bundles ......................... FAILURE [ 37.950 s]
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10:23 min
[INFO] Finished at: 2020-10-10T13:21:45+02:00
[INFO] Final Memory: 135M/512M
[INFO] ------------------------------------------------------------------------
[INFO] Static code analysis summary report is available in:
[INFO] file:/D:/dev/openhab2/git/openhab-addons/target/summary_report.html
[ERROR] Failed to execute goal com.diffplug.spotless:spotless-maven-plugin:2.0.3:check (codestyle_check) on project org.openhab.addons.reactor.bundles: The following files had format violations:
[ERROR]     pom.xml
[ERROR]         @@ -1,554 +1,554 @@
[ERROR]         -<?xml version="1.0" encoding="UTF-8" standalone="no"?>\r\n
[ERROR]         -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r\n
[ERROR]         -  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r\n
[ERROR]         -\r\n
[ERROR]         -  <modelVersion>4.0.0</modelVersion>\r\n
[ERROR]         -\r\n
[ERROR]         -  <parent>\r\n
[ERROR]         -    <groupId>org.openhab.addons</groupId>\r\n
[ERROR]         -    <artifactId>org.openhab.addons.reactor</artifactId>\r\n
[ERROR]         -    <version>3.0.0-SNAPSHOT</version>\r\n
[ERROR]         -  </parent>\r\n
[ERROR]         -\r\n
[ERROR]         -  <groupId>org.openhab.addons.bundles</groupId>\r\n
[ERROR]         -  <artifactId>org.openhab.addons.reactor.bundles</artifactId>\r\n
[ERROR]         -  <packaging>pom</packaging>\r\n
[ERROR]         -\r\n
[ERROR]         -  <name>openHAB Add-ons :: Bundles</name>\r\n
[ERROR]         -\r\n
[ERROR]         -  <modules>\r\n
[ERROR]         -    <!-- io -->\r\n
[ERROR]         -    <module>org.openhab.io.homekit</module>\r\n
[ERROR]         -    <module>org.openhab.io.hueemulation</module>\r\n
[ERROR]         -    <module>org.openhab.io.imperihome</module>\r\n
[ERROR]         -    <module>org.openhab.io.neeo</module>\r\n
[ERROR]         -    <module>org.openhab.io.openhabcloud</module>\r\n
[ERROR]         -    <module>org.openhab.io.transport.modbus</module>\r\n
[ERROR]         -    <!-- transformations -->\r\n
[ERROR]         -    <module>org.openhab.transform.bin2json</module>\r\n
[ERROR]         -    <module>org.openhab.transform.exec</module>\r\n
[ERROR]         -    <module>org.openhab.transform.javascript</module>\r\n
[ERROR]         -    <module>org.openhab.transform.jinja</module>\r\n
[ERROR]         -    <module>org.openhab.transform.jsonpath</module>\r\n
[ERROR]         -    <module>org.openhab.transform.map</module>\r\n
[ERROR]         -    <module>org.openhab.transform.regex</module>\r\n
[ERROR]         -    <module>org.openhab.transform.scale</module>\r\n
[ERROR]         -    <module>org.openhab.transform.xpath</module>\r\n
[ERROR]         -    <module>org.openhab.transform.xslt</module>\r\n
[ERROR]         -    <!-- bindings -->\r\n
[ERROR]         -    <module>org.openhab.binding.adorne</module>\r\n
[ERROR]         -    <module>org.openhab.binding.airquality</module>\r\n
[ERROR]         -    <module>org.openhab.binding.airvisualnode</module>\r\n
[ERROR]         -    <module>org.openhab.binding.alarmdecoder</module>\r\n
[ERROR]         -    <module>org.openhab.binding.allplay</module>\r\n
[ERROR]         -    <module>org.openhab.binding.amazondashbutton</module>\r\n
[ERROR]         -    <module>org.openhab.binding.amazonechocontrol</module>\r\n
[ERROR]         -    <module>org.openhab.binding.ambientweather</module>\r\n
[ERROR]         -    <module>org.openhab.binding.astro</module>\r\n
[ERROR]         -    <module>org.openhab.binding.atlona</module>\r\n
[ERROR]     ... (1060 more lines that didn't fit)
[ERROR] Run 'mvn spotless:apply' to fix these violations.
lolodomo commented 4 years ago

I even don't find this project org.openhab.addons.reactor.bundles in the repo.

And the Static code analysis summary report contains no additional information.

Just to mention this is maven run just after cloning the git repo and after installing a new JDK 11.

$ git branch
* main

$ git status
On branch main
Your branch is up-to-date with 'origin/main'.
nothing to commit, working tree clean

$ java -version
openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.8+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.8+10, mixed mode)

$ mvn -version
Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-03T21:39:06+02:00)
Maven home: C:\Program Files\apache-maven-3.5.0
Java version: 11.0.8, vendor: AdoptOpenJDK
Java home: C:\Program Files\AdoptOpenJDK\jdk-11.0.8.10-hotspot
Default locale: fr_FR, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
J-N-K commented 4 years ago

I run into that problem sometimes, too. I guess it‘s something with the git line-ending setting.

You can use -D“spotless.check.skip“=true to skip the check.

lolodomo commented 4 years ago

I got the same error when running mvn clean install -D“spotless.check.skip“=true

lolodomo commented 4 years ago

Check bypassed if I use the following command: mvn clean install -Dspotless.check.skip=true without the ""

This is probably something to add in the documentation in addtion to -DskipChecks and -DskipTests.

lolodomo commented 4 years ago

I am on Windows. You say if could be git line-ending setting. Could it be a wrong line encoding of this POM file ?

J-N-K commented 4 years ago

My feeling is that it‘s more a spotless bug (could be it doesn‘t detect the correct line-ending).

J-N-K commented 4 years ago

Very interestingnit works for you without the "". It‘s not working for me without. Are you using cmd („Eingabeaufforderung“ in german, not sure how it is labelled in other languages) or Powershell?

lolodomo commented 4 years ago

It was run from a Git Bash window.

lolodomo commented 4 years ago

With spotless checking disabled, the build succeeded.

lolodomo commented 4 years ago

It takes 1h14'. I have the feeling it takes largely more time than before (OH2) (twice the time ?). Here are the bindings that took more than 30s to build:

[INFO] openHAB Add-ons :: Bundles :: Adorne Binding ....... SUCCESS [ 45.838 s]
[INFO] openHAB Add-ons :: Bundles :: Chromecast Binding ... SUCCESS [ 56.020 s]
[INFO] openHAB Add-ons :: Bundles :: IO :: Modbus Transport SUCCESS [ 41.393 s]
[INFO] openHAB Add-ons :: Bundles :: Netatmo Binding ...... SUCCESS [ 45.396 s]
[INFO] openHAB Add-ons :: Bundles :: Smartmeter Binding ... SUCCESS [ 55.726 s]
[INFO] openHAB Add-ons :: Bundles :: Tellstick Binding .... SUCCESS [ 36.847 s]
[INFO] openHAB Add-ons :: Bundles :: IO :: Homekit ........ SUCCESS [ 32.935 s]
[INFO] openHAB Add-ons :: Bundles :: IO :: Hue Emulation Service SUCCESS [01:11 min]
[INFO] openHAB Add-ons :: Bundles :: Persistence Service :: DynamoDB SUCCESS [ 50.583 s]
[INFO] openHAB Add-ons :: Bundles :: Persistence Service :: InfluxDB SUCCESS [ 44.463 s]
[INFO] openHAB Add-ons :: Bundles :: Persistence Service :: JDBC SUCCESS [ 44.501 s]
[INFO] openHAB Add-ons :: Bundles :: Persistence Service :: JPA SUCCESS [ 52.672 s]
[INFO] openHAB Add-ons :: Bundles :: Voice :: Mary Text-to-Speech SUCCESS [01:17 min]
[INFO] openHAB Add-ons :: Integration Tests :: Feed Binding Tests SUCCESS [02:46 min]
[INFO] openHAB Add-ons :: Integration Tests :: Nest Binding Tests SUCCESS [ 32.563 s]
[INFO] openHAB Add-ons :: Integration Tests :: Systeminfo Binding Tests SUCCESS [01:02 min]

It only takes 18'54'' if I skip checks and tests.

wborn commented 4 years ago

It was run from a Git Bash window.

It might cause Spotless to think you prefer Unix-like line endings while Git thinks you prefer DOS/Windows line endings.

See also the Spotless line endings documentation:

Git has opinions about line endings, and if Spotless and git disagree, then you're going to have a bad time.

The only increase in build times I have noticed is due to more add-ons having been merged recently. I added some more options to the README that you can use to improve build times in https://github.com/openhab/openhab-addons/pull/8767.

Try disabling feature verification and a parallel build, e.g.:

mvn clean install -DskipChecks=true -DskipTests=true -Dfeatures.verify.skip=true -Dspotless.check.skip=true -T 1C

With that it only takes ~1 minute to build all add-ons on my machine.

lolodomo commented 4 years ago

The result (error) is the same if I use Windows PowerShell.

rogierhofboer commented 4 years ago

@wborn I think you are right about the line endings. It seems if you checkout .xml files with Linux \n file endings on Windows maven finds the file invalid (which I can imagine), but if you checkout with Windows line endings \r\n spotless does think the file has bad formatting.

If you let spotless allow Windows line endings on Windows (if this is possible, didn't check yet) and you commit them with Windows line endings, you have mixed Linux and Windows line endings in the repository, also the spotless checks of the buildserver will fail. Still I think this is the best solution and if a Windows user commits files with the wrong line endings, the commits won't be merged until the line endings are 'correct' (i.e. Linux).

One way to have better control as project over line endings is to add a .gitattributes file to the project with:

* text=auto

and if needed specify which file need to be handled as text if autodetection fails:

*.xml text
*.java text

See also: https://github.com/diffplug/spotless/issues/35

I think .gitattributes should be added to the project and spotless should be to configured to lineEndings 'GIT_ATTRIBUTES'

wborn commented 4 years ago

Looks like the .gitattributes wasn't added when Spotless was activated on the master/main branch. We already have this file on the 2.5.x branch, see: https://github.com/openhab/openhab-addons/blob/2.5.x/.gitattributes I'll create some PRs to add it to this branch and the other projects.

rogierhofboer commented 4 years ago

@wborn Thanks! _Note: I just learned GITATTRIBUTES as line endings option is the default (and recommended) configuration for spotless.

wborn commented 4 years ago

I hope it also solves @lolodomo's issues. If you did not have them on the 2.5.x branch they should now be solved as well. :-)

rogierhofboer commented 4 years ago

It solves the problem for me :)

lolodomo commented 4 years ago

I updated my local repo but unfortunately I still have the same problem when I try to compile the main branch.

rogierhofboer commented 4 years ago

Damn sorry @wborn.... @lolodomo is correct.. I've retried with a full clean checkout and build and it fails again (with .gitattributes added by hand for openhab-core).

If it did work on 2.5.9, what else is different?

rogierhofboer commented 4 years ago

I think I know what might go wrong. openhab-core/tools/static-code-analysis/checkstyle/ruleset.properties defines:

checkstyle.headerCheck.content=^/\\*\\*$\\n^ \\* Copyright \\(c\\) {0}-{1} Contributors to the openHAB project$\\n^ \\*$\\n^ \\* See the NOTICE file\\(s\\) distributed with this work for additional$\\n^ \\* information.$\\n^ \\*$\\n^ \\* This program and the accompanying materials are made available under the$\\n^ \\* terms of the Eclipse Public License 2\\.0 which is available at$\\n^ \\* http://www.eclipse.org/legal/epl\\-2\\.0$\\n^ \\*$\\n^ \\* 

With explicit linux line endings... This is also where I now get the error (which is different then before)

wborn commented 4 years ago

Perhaps there is one of the @openhab/add-ons-maintainers who uses Windows and can check if there are still Spotless issues on the main branch and what could fix them? I have no issues or easy ways to reproduce this on Ubuntu. :wink:

rogierhofboer commented 4 years ago

I don't think it is the openhab-core/tools/static-code-analysis/checkstyle/ruleset.properties
\n seems to work, changing it to \r\n gives pattern match errors. If addons do build I could check how they are configured.

rogierhofboer commented 4 years ago

For some reason spotless seems to ignore .gitattributes on master. I am lost why it is. Even setting the value to crlf instead of auto does not make stop complaining line endings should be \n only.

wborn commented 4 years ago

Try the main branch instead of master. The master branch is no longer used.

rogierhofboer commented 4 years ago

openhab-core still uses master I know this issue is in openhab-addons, but the problem is also present on openhab-core.

rogierhofboer commented 4 years ago

https://github.com/diffplug/spotless/issues/540 related? Looking into it...

J-N-K commented 4 years ago

I get the same error (on Win 10) if I start from the root-POM. Building single projects with -pl works. The interesting thing is, that mvn clean install -rf :org.openhab.addons.reactor.bundles also works.

lolodomo commented 4 years ago

I can confirm that build from inside a binding is working. Problem is when you build from the repo root folder.

J-N-K commented 3 years ago

git config core.eol=crlf solves the problem. This is not a problem since autcrlf=true takes precendence and git's behaviour stays unchanged.

nedtwigg commented 3 years ago

You might want * text eol=native, see https://github.com/diffplug/spotless/issues/540

hmerk commented 2 years ago

Is this still an open issue ?

wborn commented 2 years ago

For me it works fine on Windows using:

git config --global core.autocrlf false
git config --global core.eol crlf
lolodomo commented 2 years ago

I have to test these settings.

wborn commented 2 years ago

If it works better we probably want to update the developer docs as well. Sometimes those .gitattributes changes end up in PRs by Windows contributors. :confused:

lolodomo commented 2 years ago

For me it works fine on Windows using:

git config --global core.autocrlf false
git config --global core.eol crlf

Tried and working. Thank you