Explained how to suppress dependency-scanning in documentation
authorKai Moritz <km@juplo.de>
Tue, 28 Oct 2014 22:37:45 +0000 (23:37 +0100)
committerKai Moritz <kai@juplo.de>
Tue, 11 Nov 2014 13:38:01 +0000 (14:38 +0100)
Also added a test-case to be sure, that dependency-scanning is skipped, if
the parameter "dependencyScanning" is set to "none".

src/it/ignored-dependency/ignored/pom.xml [new file with mode: 0644]
src/it/ignored-dependency/ignored/src/main/java/ignored/IgnoredEntity.java [new file with mode: 0644]
src/it/ignored-dependency/main/pom.xml [new file with mode: 0644]
src/it/ignored-dependency/main/src/main/java/main/MainEntity.java [new file with mode: 0644]
src/it/ignored-dependency/main/src/main/resources/META-INF/persistence.xml [new file with mode: 0644]
src/it/ignored-dependency/pom.xml [new file with mode: 0644]
src/it/ignored-dependency/schema.sql [new file with mode: 0644]
src/it/ignored-dependency/verify.bsh [new file with mode: 0644]
src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java
src/site/xhtml/pitfalls.xhtml

diff --git a/src/it/ignored-dependency/ignored/pom.xml b/src/it/ignored-dependency/ignored/pom.xml
new file mode 100644 (file)
index 0000000..28e8ab9
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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>de.juplo</groupId>
+  <artifactId>ignored</artifactId>
+  <version>1</version>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.hibernate</groupId>
+      <artifactId>hibernate-core</artifactId>
+      <version>4.3.5.Final</version>
+    </dependency>
+  </dependencies>
+
+  <properties>
+    <maven.compiler.source>1.7</maven.compiler.source>
+    <maven.compiler.target>1.7</maven.compiler.target>
+  </properties>
+
+</project>
diff --git a/src/it/ignored-dependency/ignored/src/main/java/ignored/IgnoredEntity.java b/src/it/ignored-dependency/ignored/src/main/java/ignored/IgnoredEntity.java
new file mode 100644 (file)
index 0000000..afb73c3
--- /dev/null
@@ -0,0 +1,15 @@
+package ignored;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+@Entity
+public class IgnoredEntity
+{
+  @Id
+  @GeneratedValue
+  Long id;
+
+  String name;
+}
diff --git a/src/it/ignored-dependency/main/pom.xml b/src/it/ignored-dependency/main/pom.xml
new file mode 100644 (file)
index 0000000..d198fc9
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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>de.juplo</groupId>
+  <artifactId>main</artifactId>
+  <version>1</version>
+  <packaging>jar</packaging>
+  <name>main</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.hibernate</groupId>
+      <artifactId>hibernate-core</artifactId>
+      <version>4.3.5.Final</version>
+    </dependency>
+    <dependency>
+      <groupId>de.juplo</groupId>
+      <artifactId>ignored</artifactId>
+      <version>1</version>
+    </dependency>
+  </dependencies>
+
+  <properties>
+    <maven.compiler.source>1.7</maven.compiler.source>
+    <maven.compiler.target>1.7</maven.compiler.target>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>de.juplo</groupId>
+        <artifactId>hibernate4-maven-plugin</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <goals>
+              <goal>export</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <target>NONE</target>
+          <format>true</format>
+          <type>CREATE</type>
+          <hibernateDialect>org.hibernate.dialect.PostgreSQL9Dialect</hibernateDialect>
+          <scanDependencies>none</scanDependencies>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/src/it/ignored-dependency/main/src/main/java/main/MainEntity.java b/src/it/ignored-dependency/main/src/main/java/main/MainEntity.java
new file mode 100644 (file)
index 0000000..a86f809
--- /dev/null
@@ -0,0 +1,19 @@
+package main;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Transient;
+
+import ignored.IgnoredEntity;
+
+@Entity
+public class MainEntity
+{
+  @Id
+  @GeneratedValue
+  long id;
+
+  @Transient
+  IgnoredEntity ignoredEntity;
+}
diff --git a/src/it/ignored-dependency/main/src/main/resources/META-INF/persistence.xml b/src/it/ignored-dependency/main/src/main/resources/META-INF/persistence.xml
new file mode 100644 (file)
index 0000000..a419eda
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence version="2.0"
+       xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+        http://java.sun.com/xml/ns/persistence
+        http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
+       <persistence-unit name="primary">
+               <jta-data-source>java:jboss/datasources/PostgreSQLDS</jta-data-source>
+
+               <class>dependent.DependentEntity</class>
+
+               <properties>
+                       <property name="hibernate.hbm2ddl.auto" value="create-drop" />
+                       <property name="hibernate.show_sql" value="true" />
+               </properties>
+       </persistence-unit>
+</persistence>
diff --git a/src/it/ignored-dependency/pom.xml b/src/it/ignored-dependency/pom.xml
new file mode 100644 (file)
index 0000000..27dd299
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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/maven-v4_0_0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>de.juplo</groupId>
+  <artifactId>ignored-dependency</artifactId>
+  <name>Hibernate 4 Maven Plugin - Ignored Dependen Test</name>
+  <version>1</version>
+  <packaging>pom</packaging>
+
+  <modules>
+    <module>ignored</module>
+    <module>main</module>
+  </modules>
+
+</project>
diff --git a/src/it/ignored-dependency/schema.sql b/src/it/ignored-dependency/schema.sql
new file mode 100644 (file)
index 0000000..510de4f
--- /dev/null
@@ -0,0 +1,7 @@
+
+    create table MainEntity (
+        id int8 not null,
+        primary key (id)
+    );
+
+    create sequence hibernate_sequence;
diff --git a/src/it/ignored-dependency/verify.bsh b/src/it/ignored-dependency/verify.bsh
new file mode 100644 (file)
index 0000000..47470ce
--- /dev/null
@@ -0,0 +1,7 @@
+import de.juplo.test.FileComparator;
+
+
+FileComparator comparator = new FileComparator(basedir);
+
+if (!comparator.isEqual("schema.sql","main/target/schema.sql"))
+  return false;
index fa4ce6a..85ae518 100644 (file)
@@ -143,6 +143,9 @@ public class Hbm2DdlMojo extends AbstractMojo
    * scanned for annotated classes. Multiple scopes can be seperated by
    * white space or commas.
    * <p>
+   * If you do not want any dependencies to be scanned for annotated
+   * classes, set this parameter to <code>none</code>.
+   * <p>
    * The plugin does not scan for annotated classes in transitive
    * dependencies. If some of your annotated classes are hidden in a
    * transitive dependency, you can simply add that dependency explicitly.
index 5000695..90e0924 100644 (file)
@@ -151,7 +151,7 @@ mvn hibernate4:export -Dhibernate.export.force=true</pre>
   executed, you can configure that explicitly like this:
   </p>
   <pre class="prettyprint linenums lang-html">
-&gt;plugin&lt;
+&lt;plugin&gt;
   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
   ...
@@ -163,5 +163,21 @@ mvn hibernate4:export -Dhibernate.export.force=true</pre>
   Background-information for this design-decission can be found on the extra
   page <a href="./skip.html">To skip or not to skip: that is the question</a>...
   </p>
+  <h2>I do not want my dependencies to be scanned for hibernate annotations</h2>
+  <p>
+    If you do not want your dependencies to be scanned for hibernate annotations,
+    you can pass <code>-Dhibernate.export.scan_dependencies=none</code> to maven
+    or set <code>scanDependencies</code> to <code>none</code> in the configuration
+    of the plugin like this:
+  </p>
+  <pre class="prettyprint linenums lang-html">
+&lt;plugin&gt;
+  &lt;groupId&gt;de.juplo&lt;/groupId&gt;
+  &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
+  ...
+  &lt;configuration&gt;
+    &lt;scanDependencies&gt;none&lt;/scanDependencies&gt;
+  &lt;/configuration&gt;
+&lt;/plugin&gt;</pre>
  </body>
 </html>