Skip to content

Commit

Permalink
Add ability to pass system properties/env vars to test resources service
Browse files Browse the repository at this point in the history
This commit adds 2 configuration properties for the test resources service,
making it possible to pass either system properties or environment variables
at startup.

This will be useful in order to configure the logging level of the server.
For example, one can add:

```
micronaut {
   testResources {
      serverSystemProperties.put("logger.levels.io.micronaut", "TRACE")
   }
}
```
  • Loading branch information
melix committed Jan 9, 2025
1 parent 61f0604 commit 3562a47
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ private TaskProvider<StartTestResourcesService> createStartServiceTask(Configura
task.getStandalone().set(isStandalone);
task.getClassDataSharingDir().convention(cdsDir);
task.getUseClassDataSharing().convention(JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17));
task.getSystemProperties().convention(config.getServerSystemProperties());
task.getEnvironment().convention(config.getServerEnvironment());
task.getDebugServer().convention(config.getDebugServer());
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.MapProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Classpath;
import org.gradle.api.tasks.Input;
Expand Down Expand Up @@ -173,6 +174,12 @@ public abstract class StartTestResourcesService extends DefaultTask {
@Internal
public abstract DirectoryProperty getClassDataSharingDir();

@Input
public abstract MapProperty<String, String> getSystemProperties();

@Input
public abstract MapProperty<String, String> getEnvironment();

@Inject
protected abstract ExecOperations getExecOperations();

Expand Down Expand Up @@ -219,6 +226,8 @@ private void startService(ServerUtils.ProcessParameters processParameters) {
spec.setClasspath(getObjects().fileCollection().from(classpath));
spec.setJvmArgs(processParameters.getJvmArguments());
processParameters.getSystemProperties().forEach(spec::systemProperty);
getSystemProperties().get().forEach(spec::systemProperty);
getEnvironment().get().forEach(spec::environment);
processParameters.getArguments().forEach(spec::args);
});
} catch (GradleException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.micronaut.testresources.buildtools.KnownModules;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.MapProperty;
import org.gradle.api.provider.Property;

/**
Expand Down Expand Up @@ -110,4 +111,23 @@ public interface TestResourcesConfiguration extends KnownModules {
* @return the server idle timeout
*/
Property<Integer> getServerIdleTimeoutMinutes();

/**
* System properties to be set on the test resources service JVM.
* @return the system properties
*/
MapProperty<String, String> getServerSystemProperties();

/**
* Environment variables to be set on the test resources service JVM.
* @return the environment variables
*/
MapProperty<String, String> getServerEnvironment();

/**
* Set this property to true if you want to start the test resources service
* with a debugger attached.
* @return the debug property
*/
Property<Boolean> getDebugServer();
}

0 comments on commit 3562a47

Please sign in to comment.