package com.example;
public interface ServiceInterface {
void doSomething();
}
package com.example;
public class ServiceImpl implements ServiceInterface {
@Override
public void doSomething() {
System.out.println("Doing something...");
}
}
package com.example;
import com.google.auto.service.AutoService;
@AutoService(ServiceInterface.class)
public class ServiceImpl implements ServiceInterface {
@Override
public void doSomething() {
System.out.println("Doing something...");
}
}
<build>
<plugins>
<plugin>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>1.0-rc7</version>
<executions>
<execution>
<goals>
<goal>service</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
groovy
plugins {
id 'java-library'
id 'com.google.auto.service' version '1.0-rc7'
}
import com.example.ServiceInterface;
import java.util.ServiceLoader;
public class Main {
public static void main(String[] args) {
ServiceLoader<ServiceInterface> services = ServiceLoader.load(ServiceInterface.class);
for (ServiceInterface service : services) {
service.doSomething();
}
}
}