phax / ph-schematron

Java Schematron library that supports XSLT and native application
Apache License 2.0
112 stars 36 forks source link

Using ph-schematron 5.0.8 from gradle 5.0 ... #72

Closed aanno2 closed 5 years ago

aanno2 commented 5 years ago

... I encounter the following error:

* What went wrong:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
   > Could not resolve com.helger:ph-jaxb-pom:1.0.0.
     Required by:
         project : > com.helger:ph-schematron:5.0.8 > com.helger:ph-jaxb:9.2.0
      > Could not resolve com.helger:ph-jaxb-pom:1.0.0.
         > Could not parse POM https://jcenter.bintray.com/com/helger/ph-jaxb-pom/1.0.0/ph-jaxb-pom-1.0.0.pom
            > Could not find org.glassfish.jaxb:jaxb-bom:${jaxb.version}.

For me, it looks like that '${jaxb.version}' is not defined when using gradle instead of maven. How can I avoid the problem?

phax commented 5 years ago

I think the basic problem, is that ph-jaxb-pom POM cannot be resolved. It's a "POM only" project and resides on http://repo2.maven.org/maven2/com/helger/ph-jaxb-pom/1.0.0/ - please try including it from this server and check again. Thanks.

aanno commented 5 years ago

Well, I also asked the question at a gradle discussion. The answer was:

Gradle does not support JDK based profile activation.

The answer also refers to this stackoverflow answer.

For me, it looks like that using ph-schematron from gradle is not that easy currently. The problem is not that http://repo2.maven.org/maven2/com/helger/ph-jaxb-pom/1.0.0/ could not be resolved. The problem is that gradle does not like pom files with the version resolved from a property (${jabx.version}) ...

aanno commented 5 years ago

As addition: Currently, I'm including ph-schematron in my gradle 5.1.1 (kotlin-based) build with the following

    api("com.helger", "ph-schematron", "5.0.8") {
        exclude("com.helger", "ph-jaxb")
        exclude("com.helger", "ph-jaxb-pom")
        exclude("org.glassfish.jaxb", "jaxb-bom")
    }

Hence, I'm (explicitly) excluding all the jaxb parent-pom/bom dependency stuff. If I run into something missing, I (also) explicitly add this directly. But this is only a work-around.

phax commented 5 years ago

@aanno Thanks for pointing out that issue with Gradle. As I'm not using Gradle (and not plans to do so), I'm stuck with the Maven properties files. But what I did is to document the needed artefacts, and maybe you can create a Gradle setup that I could add to the documentation. See https://github.com/phax/ph-jaxb-pom#gradle-usage hth

phax commented 5 years ago

I assume this works now. If not, please re-open.

tofi86 commented 5 years ago

Note for future gradle users, this was the only way I could get it working with Gradle 4.10:

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    ....

    // https://github.com/phax/ph-schematron/issues/72#issuecomment-453734138
    classpath('com.helger:ph-schematron:5.2.0') {
      exclude group: 'com.helger', module: 'ph-jaxb'
      exclude group: 'com.helger', module: 'ph-jaxb-pom'
      exclude group: 'org.glassfish.jaxb', module: 'jaxb-bom'
    }
    classpath 'org.glassfish.jaxb:jaxb-core:2.2.11'
    classpath 'org.glassfish.jaxb:jaxb-runtime:2.2.11'
    classpath 'com.sun.istack:istack-commons-runtime:2.21'
  }
}

// import ph-schematron classes for pure schematron validation
import com.helger.schematron.ISchematronResource
import com.helger.schematron.pure.SchematronResourcePure

task validateSchematron {
  group = 'XXXX'
  description 'YYYYY'

  doLast {
    File xsdSchematron = new File("$projectDir/sch/test.sch");
    validationFiles.each{ xml ->
      println "Validate $xml"

      final ISchematronResource aResPure = SchematronResourcePure.fromFile(xsdSchematron);
      if (!aResPure.isValidSchematron()) {
        throw new IllegalArgumentException ("Invalid Schematron!");
      }
      def schRes = aResPure.getSchematronValidity(new StreamSource(xml)).isValid();
      if(schRes) {
        println "... SCHEMATRON OK"
      } else {
        println "... SCHEMATRON FAILED"
      }
    }

  }
}
phax commented 5 years ago

Thanks @tofi86 👍 I assume this is in combination with Java 8? For Java 9+ you should switch to the JAXB 2.3 modules...

tofi86 commented 5 years ago

I assume this is in combination with Java 8? For Java 9+ you should switch to the JAXB 2.3 modules...

Yes, its for a Java 8 project.