Skip to content

Latest commit

 

History

History
142 lines (109 loc) · 3.42 KB

README.adoc

File metadata and controls

142 lines (109 loc) · 3.42 KB

Coat

Coat

Coat - Config of Annotated Types

Easy and typesafe config objects.

What is Coat

Coat is an annotation processor to generate classes for reading configuration values into typesafe objects.

The generated config implementation is

  • easy to use

  • type-safe

  • very fast

  • thread-safe

Short Usage

  1. Define an interface representing your config object.

    import de.poiu.coat.annotation.Coat;
    
    @Coat.Config
    public interface MyConfig {
      public String appName();
    
      public int listenPort();
    
      public Optional<String> description();
    }
  2. Let the Coat annotation processor create the concrete implementation.

  3. Use the generated class.

    try {
      final MyConfig config= MyConfigBuilder.from(new File("/path/to/config.properties"));
    
      final String appName= config.appName();
      final int listenPort= config.listenPort();
      config.description().ifPresent(
        …
      );
    } catch (final ConfigValidationException ex) {
      System.err.println("Error in config file:\n" + ex.getValidationResult().toString());
      System.exit(1);
    }

Prerequisites

Coat has no runtime dependencies on other libraries.

The annotation processor has some dependencies on other libraries (which is why it is recommended to use maven as it resolves those dependencies automatically), but none of them are needed at runtime.

Coat can be used with Java 11 or higher.

Installation

To use Coat in a maven based project use the following maven coordinates:

    <!-- Contains the annotations and converters. Needed at runtime. -->
    <dependency>
      <groupId>de.poiu.coat</groupId>
      <artifactId>coat-runtime</artifactId>
      <version>2.0.2</version>
    </dependency>

    <build>
      <plugins>
        <!-- The annotation processor. Not needed at runtime. -->
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <configuration>
            <annotationProcessorPaths>
              <path>
                <groupId>de.poiu.coat</groupId>
                <artifactId>coat-processor</artifactId>
                <version>2.0.2</version>
              </path>
            </annotationProcessorPaths>
          </configuration>
        </plugin>
      </plugins>
    </build>

Otherwise download the jar-file of Coat from the Download page and put it into the classpath of your application.

Usage

For a more thorough description of the possibilities of Coat read the full documentation.

License

Coat is licensed under the terms of the Apache license 2.0.