Skip to content

Instantly share code, notes, and snippets.

@SelvinPL
Last active March 28, 2023 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SelvinPL/f082f4507b39fdf132fda00ae9bd9ff8 to your computer and use it in GitHub Desktop.
Save SelvinPL/f082f4507b39fdf132fda00ae9bd9ff8 to your computer and use it in GitHub Desktop.
Download maven and unpack and print all txt files in downloaded artifacts
<?xml version="1.0"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="DisplayMessages">
<ItemGroup>
<MavenArtifact Include="commons-compress-1.23.0" Group="org.apache.commons" Artifact="commons-compress" Version="1.23.0" />
<MavenArtifact Include="commons-compress-1.22" Group="org.apache.commons" Artifact="commons-compress" Version="1.22" />
</ItemGroup>
<Target Name="DownloadArtifacts" BeforeTargets="UnzipArchive">
<DownloadFile
SourceUrl="https://repo1.maven.org/maven2/$([MSBuild]::ValueOrDefault('%(MavenArtifact.Group)', '').Replace('.', '/'))/$([MSBuild]::ValueOrDefault('%(MavenArtifact.Artifact)', '').Replace('.', '/'))/%(MavenArtifact.Version)/%(MavenArtifact.Artifact)-%(MavenArtifact.Version).jar"
DestinationFolder="artifacts">
<Output TaskParameter="DownloadedFile" ItemName="DownloadedArtifact"/>
</DownloadFile>
</Target>
<Target Name="UnzipArchive" BeforeTargets="DisplayMessages">
<Unzip
SourceFiles="%(DownloadedArtifact.Identity)"
DestinationFolder="%(RelativeDir)\%(Filename)"
OverwriteReadOnlyFiles="true"
/>
</Target>
<Target Name="DisplayMessages" BeforeTargets="CoreCompile">
<ItemGroup>
<TextFilesInArtifacts Include="artifacts/**/*.txt" />
</ItemGroup>
<Message Importance="high" Text="All txt files in artifacts: "/>
<Message Importance="high" Text="%09%(TextFilesInArtifacts.Identity)"/>
</Target>
</Project>
@SelvinPL
Copy link
Author

Usage

msbuild /verbosity:minimal

expected output (PL)

MSBuild version 17.5.1+f6fdcf537 for .NET Framework

  Pobieranie z lokalizacji "https://repo1.maven.org/maven2/org/apache/commons/commons-compress/1.23.0/commons-compress-
  1.23.0.jar" do lokalizacji "c:\Users\Selvin\Desktop\mavbuild\artifacts\commons-compress-1.23.0.jar" (1 062 555 B).
  Pobieranie z lokalizacji "https://repo1.maven.org/maven2/org/apache/commons/commons-compress/1.22/commons-compress-1.
  22.jar" do lokalizacji "c:\Users\Selvin\Desktop\mavbuild\artifacts\commons-compress-1.22.jar" (1 039 712 B).
  All txt files in artifacts:
        artifacts\commons-compress-1.22\META-INF\LICENSE.txt
        artifacts\commons-compress-1.22\META-INF\NOTICE.txt
        artifacts\commons-compress-1.23.0\META-INF\LICENSE.txt
        artifacts\commons-compress-1.23.0\META-INF\NOTICE.txt

or (PL already downloaded)

MSBuild version 17.5.1+f6fdcf537 for .NET Framework

  All txt files in artifacts:
        artifacts\commons-compress-1.22\META-INF\LICENSE.txt
        artifacts\commons-compress-1.22\META-INF\NOTICE.txt
        artifacts\commons-compress-1.23.0\META-INF\LICENSE.txt
        artifacts\commons-compress-1.23.0\META-INF\NOTICE.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment