title: Why is Hibernate 4.2 using jandex and classmate if its Maven POM defines them as test scope?
body: <p>I'm developing a simple example with Hibernate, using it outside any container. I'm using Maven, and thus configured the JBoss repository (see <a href="https://community.jboss.org/wiki/MavenGettingStarted-Users" rel="nofollow">https://community.jboss.org/wiki/MavenGettingStarted-Users</a>) and added the following dependencies to my project's POM:</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
      &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
      &lt;version&gt;4.2.0.CR1&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;com.h2database&lt;/groupId&gt;
      &lt;artifactId&gt;h2&lt;/artifactId&gt;
      &lt;version&gt;1.3.170&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>Then I proceeded to configure Hibernate to use H2 database like this (file hibernate.cfg.xml):</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt;
  &lt;hibernate-configuration xmlns="http://www.hibernate.org/xsd/hibernate-configuration"&gt;
      &lt;session-factory&gt;
          &lt;property name="hibernate.connection.driver_class"&gt;org.h2.Driver&lt;/property&gt;
          &lt;property name="hibernate.connection.url"&gt;jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE&lt;/property&gt;
          &lt;property name="hibernate.connection.username"&gt;sa&lt;/property&gt;
          &lt;property name="hibernate.connection.password"&gt;&lt;/property&gt;
  
          &lt;property name="hibernate.connection.pool_size"&gt;1&lt;/property&gt;
          &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.H2Dialect&lt;/property&gt;
          &lt;property name="hibernate.cache.provider_class"&gt;org.hibernate.cache.internal.NoCacheProvider&lt;/property&gt;
          &lt;property name="hibernate.show_sql"&gt;true&lt;/property&gt;
          &lt;property name="hibernate.hbm2ddl.auto"&gt;update&lt;/property&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>Finally, I created a POJO for a simple contact class, as below:</p>
  
  <pre><code>@Entity
  public class Contact {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long id;
  
      @Basic
      private String name;
  
      @Basic
      private String email;
  
      /* Getters and setters omitted for brevity. */
  }
  </code></pre>
  
  <p>Finally, I created a class that obtains a session factory, a session and finally persists an entity. The code is as below:</p>
  
  <pre><code>    ServiceRegistry registry = new ServiceRegistryBuilder().configure().buildServiceRegistry();
      MetadataSources sources = new MetadataSources(registry);
      sources.addAnnotatedClass(Contact.class);
      Metadata metadata = sources.buildMetadata();
      sessionFactory = metadata.buildSessionFactory();
  
      Contact contact = new Contact();
      /* Set some attributes. */
  
      Session session = sessionFactory.openSession();
      session.save(contact);
      session.close();
  </code></pre>
  
  <p>When I run this code, this is what I get:</p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/jandex/Indexer
      at org.hibernate.metamodel.source.annotations.AnnotationMetadataSourceProcessorImpl.prepare(AnnotationMetadataSourceProcessorImpl.java:78)
      at org.hibernate.metamodel.source.internal.MetadataImpl.prepare(MetadataImpl.java:177)
      at org.hibernate.metamodel.source.internal.MetadataImpl.&lt;init&gt;(MetadataImpl.java:162)
      at org.hibernate.metamodel.source.internal.MetadataBuilderImpl.buildMetadata(MetadataBuilderImpl.java:83)
      at org.hibernate.metamodel.MetadataSources.buildMetadata(MetadataSources.java:112)
  </code></pre>
  
  <p>Investigating the POM of the <code>org.hibernate/hibernate-core</code> dependency that I added to my project, I can see it depends on <code>org.jboss/jandex 1.0.3.Final</code>. Satisfying that dependency, I get now a <code>NoClassDefFoundError: com/fasterxml/classmate/TypeResolver</code>. Back to Hibernate's POM, it depends on <code>com.fasterxml/classmate 0.5.4</code>. Satisfying that dependency also in my project I am finally able to execute the code without any <code>NoClassDefFoundError</code>s.</p>
  
  <p>In Hibernate's POM, both jandex and classmate are defined as <code>test</code> dependencies, and that's why they are not added automatically to my project by Maven's transitive dependency resolution feature. However, why are they being required when I run my simple code? What am I doing wrong?</p>
  
  <p>Thanks in advance for any pointers.
  - Vítor</p>