Making hibernate-entitymanager and hibernate-core provided in hibernate-search-orm would harm simpler use (where you don't specify the Hibernate version). From a user's perspective, I wouldn't like the artifact I use to require me to know about their dependencies in order for them to work properly... That is, unless you meant something else when you said "optional dependencies". A solution to your issue is to specify the dependency without the version, and to fix the version using dependency management instead. Then you don't need exclusion anymore. This is actually a really common issue when building application on top of multiple external libraries, so I don't think it's worth a workaround. Unless, again, I missed the point.
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<version.org.hibernate.orm>5.1.2.Final</version.org.hibernate.orm>
<version.org.hibernate.search>5.6.0.Beta3</version.org.hibernate.search>
<slf4jVersion>1.6.4</slf4jVersion>
</properties>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-orm</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-orm</artifactId>
<version>${version.org.hibernate.search}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-elasticsearch</artifactId>
<version>${version.org.hibernate.search}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${version.org.hibernate.orm}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${version.org.hibernate.orm}</version>
</dependency>
</dependencyManagement>
I've always seen dependency management being defined in some parent pom, and actual dependencies in modules, but it should also work if done in the same pom. |