title: Getting ArtifactId and Version in Spring Boot Starter
body: <p>I am currently developing a Spring Boot Starter which will host a Restful web service with some meta-data about the running application.</p>
  
  <p>I am having difficulties extracting my artifactId and versionId from my mainfest file.  I believe my issue is that the autoconfiguration classes are being loaded before the main Test application so the manifest is not yet available to be discovered.  I am not sure if my logic here is correct of if I am approaching the problem from the wrong angle.</p>
  
  <p>I originally followed the following <a href="http://www.baeldung.com/spring-boot-custom-starter" rel="noreferrer">tutorial</a> for setup.</p>
  
  <p>This gave me 3 separate projects</p>
  
  <p><code>Generic Spring Services with no context
  AutoConfiguration project for these services
  Spring Boot starter</code></p>
  
  <p>I paired the starter with a test project as an end result.</p>
  
  <p>Currently maven is being used with Spring Boot to generate a manifest file.</p>
  
  <p><code>Implementation-Title: MyExampleProjectWithCustomStarter
  Implementation-Version: 0.0.1-SNAPSHOT
  Archiver-Version: Plexus Archiver
  Built-By: mcf
  Implementation-Vendor-Id: com.coolCompany
  Spring-Boot-Version: 1.5.4.RELEASE
  Implementation-Vendor: Pivotal Software, Inc.
  Main-Class: org.springframework.boot.loader.JarLauncher
  Start-Class: com.coolcompany.SpringBootExampleApplication
  Spring-Boot-Classes: BOOT-INF/classes/
  Spring-Boot-Lib: BOOT-INF/lib/
  Created-By: Apache Maven 3.5.0
  Build-Jdk: 1.8.0_131
  Implementation-URL: http://someurl</code></p>
  
  <p>However, when I attempt to locate the manifest file for the Example project from my generic service package I cannot find the file.</p>
  
  <pre><code>  private String getApplicationVersion(String applicationName, List&lt;Attributes&gt; manifests) {
      String unknownVersion = "0.0.0-UNKNOWN";
  
      for (Attributes attr : manifests) {
        String title = attr.getValue(IMPL_TITLE);
        String version = attr.getValue(IMPL_VERSION);
        if (version != null) {
          if (applicationName.equalsIgnoreCase(title)) {
            return title + ' ' + version;
          }
        }
      }
      log.warn(
          "Could not find MANIFEST file with '" + applicationName + "' as Implementation-Title."
          + " Meta-API will return buildVersion '" + unknownVersion + "'.");
  
      return applicationName + ' ' + unknownVersion;
    }
  
    private List&lt;Attributes&gt; loadManifestFiles() {
      List&lt;Attributes&gt; manifests = new ArrayList&lt;&gt;();
      try {
        Enumeration&lt;URL&gt; resources =
            Thread.currentThread().getContextClassLoader().getResources("/META-INF/MANIFEST.MF");
        while (resources.hasMoreElements()) {
          URL url = resources.nextElement();
          try (InputStream is = url.openStream()) {
            manifests.add(new Manifest(is).getMainAttributes());
            System.out.println("Manifest size:" + manifests.size());
          } catch (IOException e) {
            log.error("Failed to read manifest from " + url, e);
          }
        }
      } catch (IOException e) {
        log.error("Failed to get manifest resources", e);
      }
      return manifests;
    }
  </code></pre>
  
  <p>Current manifest Implementation-Titles:</p>
  
  <p><code>Spring Boot Web Starter
      Spring Boot Starter
      Spring Boot
      Spring Boot AutoConfigure
      Spring Boot Logging Starter
      null
      null
      jcl-over-slf4j
      null
      log4j-over-slf4j
      null
      Spring Boot Tomcat Starter
      Apache Tomcat
      Apache Tomcat
      Apache Tomcat
      hibernate-validator
      null
      JBoss Logging 3
      ClassMate
      jackson-databind
      Jackson-annotations
      Jackson-core
      spring-web
      spring-aop
      spring-beans
      spring-context
      spring-webmvc
      spring-expression
      Spring Boot Actuator Starter
      Spring Boot Actuator
      null
      ** MyCustom-spring-boot-starter
      ** MyGenericSpringService
      null
      null
      null
      Metrics Core
      JVM Integration for Metrics
      null
      null
      Jackson datatype: JSR310
      ** MyService-spring-boot-autoconfigure
      slf4j-api
      spring-core
  </code>
  ** Missing MyExampleProjectWithCustomStarter</p>
  
  <p>count of manifest records: 44</p>